Skip to content

Commit

Permalink
Merge PR #3597 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by rvalyi
  • Loading branch information
OCA-git-bot committed Jan 28, 2025
2 parents 2d5c76a + 3d401b1 commit 880aa2f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 77 deletions.
18 changes: 10 additions & 8 deletions l10n_br_cnpj_search/wizard/partner_cnpj_search_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,16 @@ def _get_partner_values(self, cnpj_cpf):

def default_get(self, fields):
res = super().default_get(fields)
partner_id = self.env.context.get("default_partner_id")
if partner_id:
partner_model = self.env["res.partner"]
partner = partner_model.browse(partner_id)
cnpj_cpf = punctuation_rm(partner.cnpj_cpf)
misc.punctuation_rm(self.zip)
values = self._get_partner_values(cnpj_cpf)
res.update(values)
active_model = self.env.context.get("active_model")
if active_model == "res.partner":
partner_id = self.env.context.get("default_partner_id")
if partner_id:
partner_model = self.env["res.partner"]
partner = partner_model.browse(partner_id)
cnpj_cpf = punctuation_rm(partner.cnpj_cpf)
misc.punctuation_rm(self.zip)
values = self._get_partner_values(cnpj_cpf)
res.update(values)
return res

def action_update_partner(self):
Expand Down
1 change: 0 additions & 1 deletion l10n_br_crm_cnpj_search/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import crm_lead
from . import l10n_br_base_party_mixin
14 changes: 0 additions & 14 deletions l10n_br_crm_cnpj_search/models/l10n_br_base_party_mixin.py

This file was deleted.

69 changes: 15 additions & 54 deletions l10n_br_crm_cnpj_search/wizard/partner_cnpj_search_wizard.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from erpbrasil.base import misc
from erpbrasil.base.misc import punctuation_rm

from odoo import models
Expand All @@ -9,54 +8,23 @@ class PartnerCnpjSearchWizard(models.TransientModel):

def default_get(self, fields):
res = super().default_get(fields)
lead_id = self.env.context.get("default_lead_id")
if lead_id:
active_model = self.env.context.get("active_model")
if active_model == "crm.lead":
if "currency_id" in res:
lead_model = self.env["crm.lead"]
lead = lead_model.browse(lead_id)
cnpj_cpf = punctuation_rm(lead.cnpj_cpf)
misc.punctuation_rm(self.zip)
lead_id = lead_model.browse(self.env.context.get("active_id"))
cnpj_cpf = punctuation_rm(lead_id.cnpj)
values = self._get_partner_values(cnpj_cpf)
res.update(values)
return res

def action_update_partner(self):
if self.env.context.get("default_partner_id"):
active_model = self.env.context.get("active_model")
if active_model == "crm.lead":
lead_model = self.env["crm.lead"]
lead_id = lead_model.browse(self.env.context.get("active_id"))
lead_id.partner_id.cnpj_cpf = lead_id.cnpj
values_to_update = {
"legal_name": self.legal_name,
"name": self.name,
"inscr_est": self.inscr_est,
"zip": self.zip,
"street_name": self.street_name,
"street_number": self.street_number,
"street2": self.street2,
"district": self.district,
"state_id": self.state_id.id,
"city_id": self.city_id.id,
"city": self.city_id.name,
"country_id": self.country_id.id,
"phone": self.phone,
"mobile": self.mobile,
"email": self.email,
"legal_nature": self.legal_nature,
"equity_capital": self.equity_capital,
"cnae_main_id": self.cnae_main_id.id,
"company_type": "company",
}
if self.cnae_secondary_ids:
values_to_update["cnae_secondary_ids"] = [
(6, 0, self.cnae_secondary_ids.ids)
]
if self.child_ids:
values_to_update["child_ids"] = [(6, 0, self.child_ids.ids)]
non_empty_values = {
key: value for key, value in values_to_update.items() if value
}
if non_empty_values:
self.partner_id.write(non_empty_values)

elif self.env.context.get("default_lead_id"):
values_to_update_lead = {
"name": self.name,
"partner_name": self.name,
"legal_name": self.legal_name,
Expand All @@ -68,23 +36,16 @@ def action_update_partner(self):
"district": self.district,
"state_id": self.state_id.id,
"city_id": self.city_id.id,
"city": self.city_id.name,
"country_id": self.country_id.id,
"phone": self.phone,
"mobile": self.mobile,
"email_from": self.email,
"legal_nature": self.legal_nature,
"equity_capital": self.equity_capital,
"cnae_main_id": self.cnae_main_id,
"cnae_secondary_ids": self.cnae_secondary_ids,
}
non_empty_values_lead = {
key: value for key, value in values_to_update_lead.items() if value
"cnae_main_id": self.cnae_main_id.id,
"cnae_secondary_ids": [(6, 0, self.cnae_secondary_ids.ids)]
if self.cnae_secondary_ids
else False,
}
if non_empty_values_lead:
crm_lead_id = self.env.context.get("default_lead_id")
if crm_lead_id:
lead = self.env["crm.lead"].browse(crm_lead_id)
lead.write(non_empty_values_lead)

return {"type": "ir.actions.act_window_close"}
lead_id.write({k: v for k, v in values_to_update.items() if v})
return super().action_update_partner()

0 comments on commit 880aa2f

Please sign in to comment.