|
| 1 | +# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 | + |
| 3 | +from odoo.addons.website_sale.controllers.main import WebsiteSale |
| 4 | +from odoo.http import request |
| 5 | + |
| 6 | + |
| 7 | +class L10nUYWebsiteSale(WebsiteSale): |
| 8 | + |
| 9 | + def _get_mandatory_billing_address_fields(self, country_sudo): |
| 10 | + """ Extend mandatory fields to add new identification and responsibility fields when company is Uruguay. """ |
| 11 | + mandatory_fields = super()._get_mandatory_billing_address_fields(country_sudo) |
| 12 | + if request.website.sudo().company_id.country_id.code == 'UY': |
| 13 | + mandatory_fields |= {'l10n_latam_identification_type_id', 'vat'} |
| 14 | + return mandatory_fields |
| 15 | + |
| 16 | + def _prepare_address_form_values(self, order_sudo, partner_sudo, address_type, **kwargs): |
| 17 | + rendering_values = super()._prepare_address_form_values( |
| 18 | + order_sudo, partner_sudo, address_type=address_type, **kwargs |
| 19 | + ) |
| 20 | + if request.website.sudo().company_id.country_id.code != 'UY': |
| 21 | + return rendering_values |
| 22 | + |
| 23 | + if kwargs.get('use_delivery_as_billing') and address_type == 'delivery' or address_type == 'billing': |
| 24 | + can_edit_vat = rendering_values['can_edit_vat'] |
| 25 | + LatamIdentificationType = request.env['l10n_latam.identification.type'].sudo() |
| 26 | + rendering_values.update({ |
| 27 | + 'identification': partner_sudo.l10n_latam_identification_type_id or request.env.ref('l10n_uy.it_ci').id, |
| 28 | + 'identification_types': LatamIdentificationType.search([ |
| 29 | + '|', ('country_id', '=', False), ('country_id.code', '=', 'PE') |
| 30 | + ]) if can_edit_vat else LatamIdentificationType, |
| 31 | + 'vat_label': request.env._("Identification Number"), |
| 32 | + }) |
| 33 | + |
| 34 | + return rendering_values |
| 35 | + |
| 36 | + def _get_vat_validation_fields(self): |
| 37 | + fnames = super()._get_vat_validation_fields() |
| 38 | + if request.website.sudo().company_id.account_fiscal_country_id.code == 'UY': |
| 39 | + fnames.add('l10n_latam_identification_type_id') |
| 40 | + fnames.add('name') |
| 41 | + return fnames |
0 commit comments