summaryrefslogtreecommitdiff
path: root/addons/l10n_ar/models/account_fiscal_position.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/l10n_ar/models/account_fiscal_position.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/l10n_ar/models/account_fiscal_position.py')
-rw-r--r--addons/l10n_ar/models/account_fiscal_position.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/addons/l10n_ar/models/account_fiscal_position.py b/addons/l10n_ar/models/account_fiscal_position.py
new file mode 100644
index 00000000..db42d2ce
--- /dev/null
+++ b/addons/l10n_ar/models/account_fiscal_position.py
@@ -0,0 +1,47 @@
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+from odoo import fields, models, api, _
+
+
+class AccountFiscalPosition(models.Model):
+
+ _inherit = 'account.fiscal.position'
+
+ l10n_ar_afip_responsibility_type_ids = fields.Many2many(
+ 'l10n_ar.afip.responsibility.type', 'l10n_ar_afip_reponsibility_type_fiscal_pos_rel',
+ string='AFIP Responsibility Types', help='List of AFIP responsibilities where this fiscal position '
+ 'should be auto-detected')
+
+ @api.model
+ def get_fiscal_position(self, partner_id, delivery_id=None):
+ """ Take into account the partner afip responsibility in order to auto-detect the fiscal position """
+ company = self.env.company
+ if company.country_id.code == "AR":
+ PartnerObj = self.env['res.partner']
+ partner = PartnerObj.browse(partner_id)
+
+ # if no delivery use invoicing
+ if delivery_id:
+ delivery = PartnerObj.browse(delivery_id)
+ else:
+ delivery = partner
+
+ # partner manually set fiscal position always win
+ if delivery.property_account_position_id or partner.property_account_position_id:
+ return delivery.property_account_position_id or partner.property_account_position_id
+ domain = [
+ ('auto_apply', '=', True),
+ ('l10n_ar_afip_responsibility_type_ids', '=', self.env['res.partner'].browse(
+ partner_id).l10n_ar_afip_responsibility_type_id.id),
+ ('company_id', '=', company.id),
+ ]
+ return self.sudo().search(domain, limit=1)
+ return super().get_fiscal_position(partner_id, delivery_id=delivery_id)
+
+ @api.onchange('l10n_ar_afip_responsibility_type_ids', 'country_group_id', 'country_id', 'zip_from', 'zip_to')
+ def _onchange_afip_responsibility(self):
+ if self.company_id.country_id.code == "AR":
+ if self.l10n_ar_afip_responsibility_type_ids and any(['country_group_id', 'country_id', 'zip_from', 'zip_to']):
+ return {'warning': {
+ 'title': _("Warning"),
+ 'message': _('If use AFIP Responsibility then the country / zip codes will be not take into account'),
+ }}