From 6dac419d5e2b1247a9f03333835c9b2ed9de8a1e Mon Sep 17 00:00:00 2001 From: clementthomas Date: Mon, 24 Jun 2024 09:27:36 +0200 Subject: [PATCH] [IMP] partner_phone_country_validation: bug fix on partner creation from lead --- .../models/res_partner.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/partner_phone_country_validation/models/res_partner.py b/partner_phone_country_validation/models/res_partner.py index 4d3b42c..b6b8d1a 100644 --- a/partner_phone_country_validation/models/res_partner.py +++ b/partner_phone_country_validation/models/res_partner.py @@ -11,6 +11,22 @@ class Partner(models.Model): @api.constrains('country_id','phone','mobile') def _check_country_id(self): + + #if come back quote creation from lead, update partner + country = False + if self._context.get("default_type") == 'opportunity' and self._context.get("params").get("model") == "crm.lead": + lead = self.env["crm.lead"].browse(self._context.get("params").get("id")) + country = lead.country_id + for partner in self: + if not country and (partner.phone or partner.mobile): + if self.phone: + partner.set_country_from_phone_number(partner.phone) + if self.mobile: + partner.set_country_from_phone_number(partner.mobile) + elif country: + partner.country_id = country + + #check country and raise error for partner in self: if not partner.country_id and not partner.parent_id.country_id and (partner.phone or partner.mobile): raise ValidationError(_('You must set a country for the phone number of %s'%(partner.name,)))