diff --git a/l10n_br_base/models/res_company.py b/l10n_br_base/models/res_company.py index b93548d9e68c..9aad0852d1bb 100644 --- a/l10n_br_base/models/res_company.py +++ b/l10n_br_base/models/res_company.py @@ -23,6 +23,7 @@ def _get_company_address_field_names(self): "state_tax_number_ids", "street_number", "street_name", + "street_number2", ] def _inverse_legal_name(self): @@ -41,6 +42,10 @@ def _inverse_street_number(self): for company in self: company.partner_id.street_number = company.street_number + def _inverse_street_number2(self): + for company in self: + company.partner_id.street_number2 = company.street_number2 + def _inverse_cnpj_cpf(self): for company in self: company.partner_id.cnpj_cpf = company.cnpj_cpf @@ -81,6 +86,10 @@ def _inverse_l10n_br_isuf_code(self): inverse="_inverse_legal_name", ) + country_enforce_cities = fields.Boolean( + related="partner_id.country_id.enforce_cities", readonly=True + ) + district = fields.Char( compute="_compute_address", inverse="_inverse_district", @@ -96,12 +105,18 @@ def _inverse_l10n_br_isuf_code(self): inverse="_inverse_street_number", ) + street_number2 = fields.Char( + compute="_compute_address", inverse="_inverse_street_number2" + ) + city_id = fields.Many2one( domain="[('state_id', '=', state_id)]", compute="_compute_address", inverse="_inverse_city_id", ) + type = fields.Selection(related="partner_id.type", readonly=False) + country_id = fields.Many2one(default=lambda self: self.env.ref("base.br")) cnpj_cpf = fields.Char( diff --git a/l10n_br_fiscal/models/res_company.py b/l10n_br_fiscal/models/res_company.py index 9863215e6363..89423c7ad0e4 100644 --- a/l10n_br_fiscal/models/res_company.py +++ b/l10n_br_fiscal/models/res_company.py @@ -43,11 +43,18 @@ class ResCompany(models.Model): def _get_company_address_field_names(self): partner_fields = super()._get_company_address_field_names() - return partner_fields + [ - "tax_framework", - "legal_nature_id", - "cnae_main_id", - ] + return partner_fields + ["tax_framework", "legal_nature_id", "cnae_main_id"] + + def _inverse_br_address_data(self): + for company in self: + company.partner_id.write( + { + "street_name": company.street_name, + "street_number": company.street_number, + "street_number2": company.street_number2, + "city_id": company.city_id.id, + } + ) def _inverse_legal_nature_id(self): """Write the l10n_br specific functional fields.""" @@ -64,6 +71,49 @@ def _inverse_tax_framework(self): for c in self: c.partner_id.tax_framework = c.tax_framework + @api.depends("tax_framework") + def _compute_tax_domains(self): + try: + simples_piscofins = self.env.ref( + "l10n_br_fiscal.tax_pis_cofins_simples_nacional" + ).id + ipi_outros = self.env.ref("l10n_br_fiscal.tax_ipi_outros").id + group_ipi = self.env.ref("l10n_br_fiscal.tax_group_ipi").id + group_icms = self.env.ref("l10n_br_fiscal.tax_group_icms").id + group_icmssn = self.env.ref("l10n_br_fiscal.tax_group_icmssn").id + except ValueError: + simples_piscofins = ipi_outros = group_ipi = False + group_icms = group_icmssn = False + + for rec in self: + # PIS/COFINS + if rec.tax_framework == "3": + ps_dom = [ + ("piscofins_type", "=", "company"), + ("id", "!=", simples_piscofins), + ] + else: + ps_dom = [ + ("piscofins_type", "=", "company"), + ("id", "=", simples_piscofins), + ] + + # IPI + if rec.tax_framework == "3": + ipi_dom = [("tax_group_id", "=", group_ipi), ("id", "!=", ipi_outros)] + else: + ipi_dom = [("id", "=", ipi_outros)] + + # ICMS + if rec.tax_framework == "3": + icms_dom = [("tax_group_id", "=", group_icms)] + else: + icms_dom = [("tax_group_id", "=", group_icmssn)] + + rec.piscofins_domain = str(ps_dom) + rec.ipi_domain = str(ipi_dom) + rec.icms_domain = str(icms_dom) + @api.depends("cnae_main_id", "annual_revenue", "payroll_amount") def _compute_simplified_tax(self): for record in self: @@ -111,6 +161,10 @@ def _compute_simplified_tax(self): record.currency_id.decimal_places, ) + piscofins_domain = fields.Char(compute="_compute_tax_domains") + ipi_domain = fields.Char(compute="_compute_tax_domains") + icms_domain = fields.Char(compute="_compute_tax_domains") + legal_nature_id = fields.Many2one( comodel_name="l10n_br_fiscal.legal.nature", string="Legal Nature", @@ -129,7 +183,7 @@ def _compute_simplified_tax(self): cnae_secondary_ids = fields.Many2many( comodel_name="l10n_br_fiscal.cnae", - domain="[('internal_type', '=', 'normal'), " "('id', '!=', cnae_main_id)]", + domain="[('internal_type', '=', 'normal'), ('id', '!=', cnae_main_id)]", string="Secondary CNAE", ) diff --git a/l10n_br_fiscal/views/res_company_view.xml b/l10n_br_fiscal/views/res_company_view.xml index a845175f274a..2089b1a4d9a9 100644 --- a/l10n_br_fiscal/views/res_company_view.xml +++ b/l10n_br_fiscal/views/res_company_view.xml @@ -82,11 +82,12 @@ + @@ -96,11 +97,12 @@ name="ripi" invisible="tax_framework != '3'" /> +
IPI tax will be calculed by Product NCM and Fiscal Operation.
+