From 1a163efdecc543a3e90bade7ce8e799b266103b8 Mon Sep 17 00:00:00 2001 From: Daniil Digtyar Vasilieva <daniildigtyar@gmail.com> Date: Mon, 10 Jul 2023 12:26:02 +0200 Subject: [PATCH] [IMP] energy_selfconsumption: owner creation --- .../wizards/selfconsumption_import_wizard.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/energy_selfconsumption/wizards/selfconsumption_import_wizard.py b/energy_selfconsumption/wizards/selfconsumption_import_wizard.py index b82e58466..a5e8476af 100644 --- a/energy_selfconsumption/wizards/selfconsumption_import_wizard.py +++ b/energy_selfconsumption/wizards/selfconsumption_import_wizard.py @@ -114,6 +114,16 @@ class SelfconsumptionImportWizard(models.TransientModel): owner = self.env['res.partner'].search([ '|', ('vat', '=', line_dict['owner_vat']), ('vat', '=ilike', line_dict['owner_vat']) ], limit=1) + if not owner: + try: + res = self.env['res.partner'].create({ + 'vat': line_dict['owner_vat'], + 'firstname': line_dict['owner_fistname'], + 'lastname': line_dict['owner_lastname'], + 'company_type': 'person' + }) + except Exception as e: + return False, _('Owner could not be created: {error}').format(error=e) country = self.env['res.country'].search([('code', '=', line_dict['country'])]) if not country: return False, _('Country code was not found: {code}').format(line_dict['country']) -- GitLab