summaryrefslogtreecommitdiff
path: root/addons/l10n_ar_website_sale/controllers/main.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_website_sale/controllers/main.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/l10n_ar_website_sale/controllers/main.py')
-rw-r--r--addons/l10n_ar_website_sale/controllers/main.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/addons/l10n_ar_website_sale/controllers/main.py b/addons/l10n_ar_website_sale/controllers/main.py
new file mode 100644
index 00000000..053a8a50
--- /dev/null
+++ b/addons/l10n_ar_website_sale/controllers/main.py
@@ -0,0 +1,57 @@
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+from odoo import _
+from odoo.addons.website_sale.controllers.main import WebsiteSale
+from odoo.http import request, route
+
+
+class L10nARWebsiteSale(WebsiteSale):
+
+ def _get_mandatory_fields_billing(self, country_id=False):
+ """Extend mandatory fields to add new identification and responsibility fields when company is argentina"""
+ res = super()._get_mandatory_fields_billing(country_id)
+ if request.website.sudo().company_id.country_id.code == "AR":
+ res += ["l10n_latam_identification_type_id", "l10n_ar_afip_responsibility_type_id", "vat"]
+ return res
+
+ def _get_country_related_render_values(self, kw, render_values):
+ res = super()._get_country_related_render_values(kw, render_values)
+ if request.website.sudo().company_id.country_id.code == "AR":
+ res.update({'identification': kw.get('l10n_latam_identification_type_id'),
+ 'responsibility': kw.get('l10n_ar_afip_responsibility_type_id'),
+ 'responsibility_types': request.env['l10n_ar.afip.responsibility.type'].search([]),
+ 'identification_types': request.env['l10n_latam.identification.type'].search(
+ ['|', ('country_id', '=', False), ('country_id.code', '=', 'AR')])})
+ return res
+
+ def _get_vat_validation_fields(self, data):
+ res = super()._get_vat_validation_fields(data)
+ if request.website.sudo().company_id.country_id.code == "AR":
+ res.update({'l10n_latam_identification_type_id': int(data['l10n_latam_identification_type_id'])
+ if data.get('l10n_latam_identification_type_id') else False})
+ res.update({'name': data['name'] if data.get('name') else False})
+ return res
+
+ def checkout_form_validate(self, mode, all_form_values, data):
+ """ We extend the method to add a new validation. If AFIP Resposibility is:
+
+ * Final Consumer or Foreign Customer: then it can select any identification type.
+ * Any other (Monotributista, RI, etc): should select always "CUIT" identification type"""
+ error, error_message = super().checkout_form_validate(mode, all_form_values, data)
+
+ # Identification type and AFIP Responsibility Combination
+ if request.website.sudo().company_id.country_id.code == "AR":
+ if mode[1] == 'billing':
+ id_type_id = data.get("l10n_latam_identification_type_id")
+ afip_resp_id = data.get("l10n_ar_afip_responsibility_type_id")
+
+ id_type = request.env['l10n_latam.identification.type'].browse(id_type_id) if id_type_id else False
+ afip_resp = request.env['l10n_ar.afip.responsibility.type'].browse(afip_resp_id) if afip_resp_id else False
+ cuit_id_type = request.env.ref('l10n_ar.it_cuit')
+
+ # Check if the AFIP responsibility is different from Final Consumer or Foreign Customer,
+ # and if the identification type is different from CUIT
+ if afip_resp.code not in ['5', '9'] and id_type != cuit_id_type:
+ error["l10n_latam_identification_type_id"] = 'error'
+ error_message.append(_('For the selected AFIP Responsibility you will need to set CUIT Identification Type'))
+
+ return error, error_message