Debian Codegraph @

addons/l10n_br/models/account_fiscal_position.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 # Part of Odoo. See LICENSE file for full copyright and licensing details.
3 from odoo import api, fields, models
4
5 SOUTH_SOUTHEAST = {"PR", "RS", "SC", "SP", "ES", "MG", "RJ"}
6 NORTH_NORTHEAST_MIDWEST = {
7 "AC", "AP", "AM", "PA", "RO", "RR", "TO", "AL", "BA", "CE",
8 "MA", "PB", "PE", "PI", "RN", "SE", "DF", "GO", "MT", "MS"
9 }
10
11
12 class AccountFiscalPosition(models.Model):
13 _inherit = 'account.fiscal.position'
14
15 l10n_br_fp_type = fields.Selection(
16 selection=[
17 ('internal', 'Internal'),
18 ('ss_nnm', 'South/Southeast selling to North/Northeast/Midwest'),
19 ('interstate', 'Other interstate'),
20 ],
21 string='Interstate Fiscal Position Type',
22 )
23
24 @api.model
25 def _get_fiscal_position(self, partner, delivery=None):
26 if not delivery:
27 delivery = partner
28
29 if self.env.company.country_id.code != "BR" or delivery.country_id.code != 'BR':
30 return super()._get_fiscal_position(partner, delivery=delivery)
31
32 # manually set fiscal position on partner has a higher priority
33 manual_fiscal_position = delivery.property_account_position_id or partner.property_account_position_id
34 if manual_fiscal_position:
35 return manual_fiscal_position
36
37 # Taxation in Brazil depends on both the state of the partner and the state of the company
38 if self.env.company.state_id == delivery.state_id:
39 return self.search([('l10n_br_fp_type', '=', 'internal'), ('company_id', '=', self.env.company.id)], limit=1)
40 if self.env.company.state_id.code in SOUTH_SOUTHEAST and delivery.state_id.code in NORTH_NORTHEAST_MIDWEST:
41 return self.search([('l10n_br_fp_type', '=', 'ss_nnm'), ('company_id', '=', self.env.company.id)], limit=1)
42 return self.search([('l10n_br_fp_type', '=', 'interstate'), ('company_id', '=', self.env.company.id)], limit=1)