From a513523ed65ee0a16b410a3ad765ac73bc8dc69f Mon Sep 17 00:00:00 2001 From: Sven Fuehr Date: Wed, 15 Nov 2023 14:57:11 +0100 Subject: [PATCH] [ADD] l10n_ec_website_sale: adapt eCommerce to allow EDI invoice Currently the eCommerce workflow in Ecuador lacks some information needed to issue EDI invoices. The main adaptions needed are: * Identification type and number in the checkout process (in the billing address) * SRI Payment Method in the eCommerce Payment Method SRI Payment Method * The SRI Payment Method value is required for the EDI * In the payment method form view the SRI Payment Method field is hidden if the list of fiscal countries of the selected companies does not include Ecuador. * Payment methods which do not have an associated SRI Payment Method cannot be used in the eCommerce checkout of an Ecuadorian company. * A (default) SRI Payment Method has been addeded to some payment methods to simplify the setup. * When creating an invoice from a sales order we try to compute the SRI Payment Method as follows: We consider all the SRI Payment Methods of the payment methods of the payment transactions associated with the sales order. If there is exactly 1 such SRI Payment Method we use this on the invoice. This should ensures that we can always set the SRI Payment Method on invoices created through the eCommerce flow. task-3585823 Part-of: odoo/odoo#142730 --- addons/l10n_ec_website_sale/__init__.py | 4 ++ addons/l10n_ec_website_sale/__manifest__.py | 24 +++++++ .../controllers/__init__.py | 3 + .../l10n_ec_website_sale/controllers/main.py | 44 ++++++++++++ .../data/ir_model_fields.xml | 11 +++ .../data/payment_method_data.xml | 16 +++++ .../demo/website_demo.xml | 17 +++++ addons/l10n_ec_website_sale/i18n/es.po | 68 +++++++++++++++++++ .../i18n/l10n_ec_website_sale.pot | 68 +++++++++++++++++++ .../l10n_ec_website_sale/models/__init__.py | 4 ++ .../models/payment_method.py | 18 +++++ .../l10n_ec_website_sale/models/sale_order.py | 25 +++++++ .../views/payment_method_views.xml | 18 +++++ .../views/website_sales_templates.xml | 48 +++++++++++++ 14 files changed, 368 insertions(+) create mode 100644 addons/l10n_ec_website_sale/__init__.py create mode 100644 addons/l10n_ec_website_sale/__manifest__.py create mode 100644 addons/l10n_ec_website_sale/controllers/__init__.py create mode 100644 addons/l10n_ec_website_sale/controllers/main.py create mode 100644 addons/l10n_ec_website_sale/data/ir_model_fields.xml create mode 100644 addons/l10n_ec_website_sale/data/payment_method_data.xml create mode 100644 addons/l10n_ec_website_sale/demo/website_demo.xml create mode 100644 addons/l10n_ec_website_sale/i18n/es.po create mode 100644 addons/l10n_ec_website_sale/i18n/l10n_ec_website_sale.pot create mode 100644 addons/l10n_ec_website_sale/models/__init__.py create mode 100644 addons/l10n_ec_website_sale/models/payment_method.py create mode 100644 addons/l10n_ec_website_sale/models/sale_order.py create mode 100644 addons/l10n_ec_website_sale/views/payment_method_views.xml create mode 100644 addons/l10n_ec_website_sale/views/website_sales_templates.xml diff --git a/addons/l10n_ec_website_sale/__init__.py b/addons/l10n_ec_website_sale/__init__.py new file mode 100644 index 00000000000..796c4d19bd6 --- /dev/null +++ b/addons/l10n_ec_website_sale/__init__.py @@ -0,0 +1,4 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import controllers +from . import models diff --git a/addons/l10n_ec_website_sale/__manifest__.py b/addons/l10n_ec_website_sale/__manifest__.py new file mode 100644 index 00000000000..73d500d94ff --- /dev/null +++ b/addons/l10n_ec_website_sale/__manifest__.py @@ -0,0 +1,24 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. +{ + 'name': 'Ecuadorian Website', + 'countries': ['ec'], + 'version': '1.0', + 'category': 'Accounting/Localizations/Website', + 'description': """Make ecommerce work for Ecuador.""", + 'depends': [ + 'website_sale', + 'l10n_ec', + ], + 'data': [ + 'data/ir_model_fields.xml', + 'data/payment_method_data.xml', + 'views/website_sales_templates.xml', + 'views/payment_method_views.xml', + ], + 'demo': [ + 'demo/website_demo.xml', + ], + 'installable': True, + 'auto_install': True, + 'license': 'LGPL-3', +} diff --git a/addons/l10n_ec_website_sale/controllers/__init__.py b/addons/l10n_ec_website_sale/controllers/__init__.py new file mode 100644 index 00000000000..80ee4da1c5e --- /dev/null +++ b/addons/l10n_ec_website_sale/controllers/__init__.py @@ -0,0 +1,3 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import main diff --git a/addons/l10n_ec_website_sale/controllers/main.py b/addons/l10n_ec_website_sale/controllers/main.py new file mode 100644 index 00000000000..d2d5db7c5a5 --- /dev/null +++ b/addons/l10n_ec_website_sale/controllers/main.py @@ -0,0 +1,44 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.addons.website_sale.controllers.main import WebsiteSale +from odoo.http import request + + +class L10nECWebsiteSale(WebsiteSale): + + def _get_mandatory_fields_billing(self, country_id=False): + """Extend mandatory fields to add new identification and responsibility fields when company is Ecuador""" + res = super()._get_mandatory_fields_billing(country_id) + if request.website.sudo().company_id.country_id.code == "EC": + res += ["l10n_latam_identification_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 == "EC": + res.update({ + 'identification': kw.get('l10n_latam_identification_type_id'), + 'identification_types': request.env['l10n_latam.identification.type'].search( + ['|', ('country_id', '=', False), ('country_id.code', '=', 'EC')]), + }) + return res + + def _get_vat_validation_fields(self, data): + res = super()._get_vat_validation_fields(data) + latam_id_type_data = data.get("l10n_latam_identification_type_id") + if request.website.sudo().company_id.country_id.code == "EC": + res.update({ + 'l10n_latam_identification_type_id': int(latam_id_type_data) if latam_id_type_data else False, + 'name': data.get('name', False), + }) + return res + + def _get_shop_payment_values(self, order, **kwargs): + payment_values = super()._get_shop_payment_values(order, **kwargs) + company = order.company_id + # Do not show payment methods without l10n_ec_sri_payment_id. + # Payment methods without this fields could cause issues since we require a l10n_ec_sri_payment_id to post a move. + if company.account_fiscal_country_id.code == 'EC': + payment_methods = payment_values['payment_methods_sudo'].filtered(lambda pm: bool(pm.l10n_ec_sri_payment_id)) + payment_values['payment_methods_sudo'] = payment_methods + return payment_values diff --git a/addons/l10n_ec_website_sale/data/ir_model_fields.xml b/addons/l10n_ec_website_sale/data/ir_model_fields.xml new file mode 100644 index 00000000000..7edfb92c157 --- /dev/null +++ b/addons/l10n_ec_website_sale/data/ir_model_fields.xml @@ -0,0 +1,11 @@ + + + + + res.partner + + + + diff --git a/addons/l10n_ec_website_sale/data/payment_method_data.xml b/addons/l10n_ec_website_sale/data/payment_method_data.xml new file mode 100644 index 00000000000..d0f5cd90c2e --- /dev/null +++ b/addons/l10n_ec_website_sale/data/payment_method_data.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/addons/l10n_ec_website_sale/demo/website_demo.xml b/addons/l10n_ec_website_sale/demo/website_demo.xml new file mode 100644 index 00000000000..827f0a9f3ca --- /dev/null +++ b/addons/l10n_ec_website_sale/demo/website_demo.xml @@ -0,0 +1,17 @@ + + + + + EC Company Website + + + + + + + + + diff --git a/addons/l10n_ec_website_sale/i18n/es.po b/addons/l10n_ec_website_sale/i18n/es.po new file mode 100644 index 00000000000..05032f1784c --- /dev/null +++ b/addons/l10n_ec_website_sale/i18n/es.po @@ -0,0 +1,68 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * l10n_ec_website_sale +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.1alpha1+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-11-17 13:55+0000\n" +"PO-Revision-Date: 2023-11-17 13:55+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: l10n_ec_website_sale +#: model:website,contact_us_button_url:l10n_ec_website_sale.default_website_ec +msgid "/contactus" +msgstr "/contactus" + +#. module: l10n_ec_website_sale +#: model_terms:ir.ui.view,arch_db:l10n_ec_website_sale.partner_info +msgid "" +msgstr "" + +#. module: l10n_ec_website_sale +#: model_terms:ir.ui.view,arch_db:l10n_ec_website_sale.partner_info +msgid "" +"Changing Identification type is not allowed once document(s) have been " +"issued for your account. Please contact us directly for this operation." +msgstr "Cambiar el Tipo de Identificación no esta permitido una vez que hayan factura(s) emitadas a tu cuenta. Por favor contactenos directamente para esta operación." + +#. module: l10n_ec_website_sale +#: model:ir.model.fields,field_description:l10n_ec_website_sale.field_payment_method__fiscal_country_codes +msgid "Fiscal Country Codes" +msgstr "Códigos Fiscales de País" + +#. module: l10n_ec_website_sale +#: model_terms:ir.ui.view,arch_db:l10n_ec_website_sale.address +msgid "Identification Number" +msgstr "Número de Identificación" + +#. module: l10n_ec_website_sale +#: model_terms:ir.ui.view,arch_db:l10n_ec_website_sale.partner_info +msgid "Identification Type" +msgstr "Tipo de Identificación" + +#. module: l10n_ec_website_sale +#: model:website,prevent_zero_price_sale_text:l10n_ec_website_sale.default_website_ec +msgid "Not Available For Sale" +msgstr "No disponible para la venta" + +#. module: l10n_ec_website_sale +#: model:ir.model,name:l10n_ec_website_sale.model_payment_method +msgid "Payment Method" +msgstr "Método de pago" + +#. module: l10n_ec_website_sale +#: model:ir.model.fields,field_description:l10n_ec_website_sale.field_payment_method__l10n_ec_sri_payment_id +msgid "SRI Payment Method" +msgstr "SRI Forma de pago" + +#. module: l10n_ec_website_sale +#: model:ir.model,name:l10n_ec_website_sale.model_sale_order +msgid "Sales Order" +msgstr "Pedido de venta" diff --git a/addons/l10n_ec_website_sale/i18n/l10n_ec_website_sale.pot b/addons/l10n_ec_website_sale/i18n/l10n_ec_website_sale.pot new file mode 100644 index 00000000000..ee08c4ef77f --- /dev/null +++ b/addons/l10n_ec_website_sale/i18n/l10n_ec_website_sale.pot @@ -0,0 +1,68 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * l10n_ec_website_sale +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.1alpha1+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-11-17 14:58+0000\n" +"PO-Revision-Date: 2023-11-17 14:58+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: l10n_ec_website_sale +#: model:website,contact_us_button_url:l10n_ec_website_sale.default_website_ec +msgid "/contactus" +msgstr "" + +#. module: l10n_ec_website_sale +#: model_terms:ir.ui.view,arch_db:l10n_ec_website_sale.partner_info +msgid "" +msgstr "" + +#. module: l10n_ec_website_sale +#: model_terms:ir.ui.view,arch_db:l10n_ec_website_sale.partner_info +msgid "" +"Changing Identification type is not allowed once document(s) have been " +"issued for your account. Please contact us directly for this operation." +msgstr "" + +#. module: l10n_ec_website_sale +#: model:ir.model.fields,field_description:l10n_ec_website_sale.field_payment_method__fiscal_country_codes +msgid "Fiscal Country Codes" +msgstr "" + +#. module: l10n_ec_website_sale +#: model_terms:ir.ui.view,arch_db:l10n_ec_website_sale.address +msgid "Identification Number" +msgstr "" + +#. module: l10n_ec_website_sale +#: model_terms:ir.ui.view,arch_db:l10n_ec_website_sale.partner_info +msgid "Identification Type" +msgstr "" + +#. module: l10n_ec_website_sale +#: model:website,prevent_zero_price_sale_text:l10n_ec_website_sale.default_website_ec +msgid "Not Available For Sale" +msgstr "" + +#. module: l10n_ec_website_sale +#: model:ir.model,name:l10n_ec_website_sale.model_payment_method +msgid "Payment Method" +msgstr "" + +#. module: l10n_ec_website_sale +#: model:ir.model.fields,field_description:l10n_ec_website_sale.field_payment_method__l10n_ec_sri_payment_id +msgid "SRI Payment Method" +msgstr "" + +#. module: l10n_ec_website_sale +#: model:ir.model,name:l10n_ec_website_sale.model_sale_order +msgid "Sales Order" +msgstr "" diff --git a/addons/l10n_ec_website_sale/models/__init__.py b/addons/l10n_ec_website_sale/models/__init__.py new file mode 100644 index 00000000000..5dc6dc473bc --- /dev/null +++ b/addons/l10n_ec_website_sale/models/__init__.py @@ -0,0 +1,4 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import payment_method +from . import sale_order diff --git a/addons/l10n_ec_website_sale/models/payment_method.py b/addons/l10n_ec_website_sale/models/payment_method.py new file mode 100644 index 00000000000..5d90909c22b --- /dev/null +++ b/addons/l10n_ec_website_sale/models/payment_method.py @@ -0,0 +1,18 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models + +class PaymentMethod(models.Model): + _inherit = 'payment.method' + + l10n_ec_sri_payment_id = fields.Many2one( + comodel_name="l10n_ec.sri.payment", + string="SRI Payment Method", + ) + + fiscal_country_codes = fields.Char(compute="_compute_fiscal_country_codes") + + @api.depends_context('allowed_company_ids') + def _compute_fiscal_country_codes(self): + for record in self: + record.fiscal_country_codes = ",".join(self.env.companies.mapped('account_fiscal_country_id.code')) diff --git a/addons/l10n_ec_website_sale/models/sale_order.py b/addons/l10n_ec_website_sale/models/sale_order.py new file mode 100644 index 00000000000..1e602971480 --- /dev/null +++ b/addons/l10n_ec_website_sale/models/sale_order.py @@ -0,0 +1,25 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + def _create_invoices(self, grouped=False, final=False, date=None): + """ Create invoice(s) for the given Sales Order(s). + + :param bool grouped: if True, invoices are grouped by SO id. + If False, invoices are grouped by keys returned by :meth:`_get_invoice_grouping_keys` + :param bool final: if True, refunds will be generated if necessary + :param date: unused parameter + :returns: created invoices + :rtype: `account.move` recordset + :raises: UserError if one of the orders has no invoiceable lines. + """ + moves = super()._create_invoices(grouped, final, date) + for move in moves: + if move.transaction_ids: + sri_payment_methods = move.transaction_ids.mapped('payment_method_id.l10n_ec_sri_payment_id') + if len(sri_payment_methods) == 1: + move.l10n_ec_sri_payment_id = sri_payment_methods + return moves diff --git a/addons/l10n_ec_website_sale/views/payment_method_views.xml b/addons/l10n_ec_website_sale/views/payment_method_views.xml new file mode 100644 index 00000000000..f60c2afab43 --- /dev/null +++ b/addons/l10n_ec_website_sale/views/payment_method_views.xml @@ -0,0 +1,18 @@ + + + + l10n_ec_website_sale.payment.method.form + payment.method + + + + + + + + diff --git a/addons/l10n_ec_website_sale/views/website_sales_templates.xml b/addons/l10n_ec_website_sale/views/website_sales_templates.xml new file mode 100644 index 00000000000..6cd854926e0 --- /dev/null +++ b/addons/l10n_ec_website_sale/views/website_sales_templates.xml @@ -0,0 +1,48 @@ + + + + + + + +