From 4b70f1d01f5f7edd4ad5592bc66aae8f00aacfbc Mon Sep 17 00:00:00 2001 From: Antoni Marroig Campomar Date: Mon, 23 Sep 2024 13:05:42 +0200 Subject: [PATCH] [MIG] l10n_es_pos_oca: Migration to 17.0 --- l10n_es_pos_oca/README.rst | 4 + l10n_es_pos_oca/__manifest__.py | 12 +- l10n_es_pos_oca/hooks.py | 8 +- l10n_es_pos_oca/models/pos_config.py | 4 - l10n_es_pos_oca/readme/CONTRIBUTORS.md | 2 + l10n_es_pos_oca/static/description/index.html | 4 + .../payment_screen/payment_screen.esm.js | 28 +++ .../receipt_screen/receipt/order_receipt.xml} | 1 - .../src/app/screens/store/models.esm.js | 93 ++++++++++ .../screens/ticket_screen/ticket_screen.xml} | 1 - .../screens/ticket_screen/ticket_sreen.esm.js | 17 ++ .../static/src/js/PaymentScreen.js | 36 ---- .../js/Screens/TicketScreen/TicketScreen.js | 21 --- l10n_es_pos_oca/static/src/js/models.js | 172 ------------------ .../views/res_config_settings_views.xml | 47 ++--- 15 files changed, 176 insertions(+), 274 deletions(-) create mode 100644 l10n_es_pos_oca/static/src/app/screens/payment_screen/payment_screen.esm.js rename l10n_es_pos_oca/static/src/{xml/pos.xml => app/screens/receipt_screen/receipt/order_receipt.xml} (99%) create mode 100644 l10n_es_pos_oca/static/src/app/screens/store/models.esm.js rename l10n_es_pos_oca/static/src/{xml/Screens/OrderManagementScreen/TicketScreen.xml => app/screens/ticket_screen/ticket_screen.xml} (97%) create mode 100644 l10n_es_pos_oca/static/src/app/screens/ticket_screen/ticket_sreen.esm.js delete mode 100644 l10n_es_pos_oca/static/src/js/PaymentScreen.js delete mode 100644 l10n_es_pos_oca/static/src/js/Screens/TicketScreen/TicketScreen.js delete mode 100644 l10n_es_pos_oca/static/src/js/models.js diff --git a/l10n_es_pos_oca/README.rst b/l10n_es_pos_oca/README.rst index bb0d83d1c5a..3059b9319df 100644 --- a/l10n_es_pos_oca/README.rst +++ b/l10n_es_pos_oca/README.rst @@ -137,6 +137,10 @@ Contributors - Daniel Duque +- `APSL-Nagarro `__: + + - Antoni Marroig + Maintainers ----------- diff --git a/l10n_es_pos_oca/__manifest__.py b/l10n_es_pos_oca/__manifest__.py index fe643765177..118ba5a1191 100644 --- a/l10n_es_pos_oca/__manifest__.py +++ b/l10n_es_pos_oca/__manifest__.py @@ -9,16 +9,16 @@ "Odoo Community Association (OCA)", "website": "https://github.com/OCA/l10n-spain", "license": "AGPL-3", - "version": "16.0.1.0.2", + "version": "17.0.1.0.0", "depends": ["point_of_sale"], "data": ["views/pos_views.xml", "views/res_config_settings_views.xml"], "assets": { "point_of_sale.assets": [ - "l10n_es_pos/static/src/xml/pos.xml", - "l10n_es_pos/static/src/xml/Screens/OrderManagementScreen/TicketScreen.xml", - "l10n_es_pos/static/src/js/PaymentScreen.js", - "l10n_es_pos/static/src/js/models.js", - "l10n_es_pos/static/src/js/Screens/TicketScreen/TicketScreen.js", + "l10n_es_pos_oca/static/src/app/pos.xml", + "l10n_es_pos_oca/static/src/app/Screens/ticket_screen/ticket_screen.xml", + "l10n_es_pos_oca/static/src/app/screens/payment_screen/payment_screen.js", + "l10n_es_pos_oca/static/src/app/store/models.js", + "l10n_es_pos_oca/static/src/app/screens/ticket_screen/ticket_screen.js", ], }, "installable": True, diff --git a/l10n_es_pos_oca/hooks.py b/l10n_es_pos_oca/hooks.py index 93b97984a5d..85f78cd339c 100644 --- a/l10n_es_pos_oca/hooks.py +++ b/l10n_es_pos_oca/hooks.py @@ -1,12 +1,9 @@ # Copyright 2018 David Vidal # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import SUPERUSER_ID, api - -def post_init_hook(cr, registry, vals=None): +def post_init_hook(env, vals=None): """For brand new installations""" - env = api.Environment(cr, SUPERUSER_ID, {}) IrSequence = env["ir.sequence"] pos_config = env["pos.config"].search( [("l10n_es_simplified_invoice_sequence_id", "=", False)] @@ -47,6 +44,5 @@ def post_init_hook(cr, registry, vals=None): ) -def uninstall_hook(cr, registry): - env = api.Environment(cr, SUPERUSER_ID, {}) +def uninstall_hook(env): env["ir.sequence"].search([("code", "=", "pos.config.simplified_invoice")]).unlink() diff --git a/l10n_es_pos_oca/models/pos_config.py b/l10n_es_pos_oca/models/pos_config.py index cb7d941fcd4..2c17a259a50 100644 --- a/l10n_es_pos_oca/models/pos_config.py +++ b/l10n_es_pos_oca/models/pos_config.py @@ -31,7 +31,6 @@ def _compute_simplified_invoice_sequence(self): string="Simplified Invoice IDs Sequence", help="Autogenerate for each POS created", copy=False, - readonly=True, ) l10n_es_simplified_invoice_limit = fields.Float( string="Sim.Inv limit amount", @@ -42,17 +41,14 @@ def _compute_simplified_invoice_sequence(self): ) l10n_es_simplified_invoice_prefix = fields.Char( "Simplified Invoice prefix", - readonly=True, compute="_compute_simplified_invoice_sequence", ) l10n_es_simplified_invoice_padding = fields.Integer( "Simplified Invoice padding", - readonly=True, compute="_compute_simplified_invoice_sequence", ) l10n_es_simplified_invoice_number = fields.Integer( "Sim.Inv number", - readonly=True, compute="_compute_simplified_invoice_sequence", ) diff --git a/l10n_es_pos_oca/readme/CONTRIBUTORS.md b/l10n_es_pos_oca/readme/CONTRIBUTORS.md index ef8104ff8ac..fad81e9afe8 100644 --- a/l10n_es_pos_oca/readme/CONTRIBUTORS.md +++ b/l10n_es_pos_oca/readme/CONTRIBUTORS.md @@ -16,3 +16,5 @@ - Manuel Regidor - [Factor Libre](https://factorlibre.com/): - Daniel Duque \<\> +- [APSL-Nagarro](https://www.apsl.tech): + - Antoni Marroig \<\> diff --git a/l10n_es_pos_oca/static/description/index.html b/l10n_es_pos_oca/static/description/index.html index 4d21953d58c..a777e76f510 100644 --- a/l10n_es_pos_oca/static/description/index.html +++ b/l10n_es_pos_oca/static/description/index.html @@ -484,6 +484,10 @@

Contributors

  • Daniel Duque <daniel.duque@factorlibre.com>
  • +
  • APSL-Nagarro: +
  • diff --git a/l10n_es_pos_oca/static/src/app/screens/payment_screen/payment_screen.esm.js b/l10n_es_pos_oca/static/src/app/screens/payment_screen/payment_screen.esm.js new file mode 100644 index 00000000000..82ed4b31d0e --- /dev/null +++ b/l10n_es_pos_oca/static/src/app/screens/payment_screen/payment_screen.esm.js @@ -0,0 +1,28 @@ +/** @odoo-module */ + +/* Copyright 2016 David Gómez Quilón + Copyright 2018 Tecnativa - David Vidal + Copyright 2020 Tecnativa - João Marques + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +*/ + +import {PaymentScreen} from "@point_of_sale/app/screens/payment_screen/payment_screen"; +import {patch} from "@web/core/utils/patch"; + +patch(PaymentScreen.prototype, { + async validateOrder(isForceValidate) { + const below_limit = + this.currentOrder.get_total_with_tax() <= + this.env.pos.config.l10n_es_simplified_invoice_limit; + if (this.env.pos.config.is_simplified_config) { + const order = this.currentOrder; + if (below_limit && !order.to_invoice) { + await order.set_simple_inv_number(); + } else { + // Force invoice above limit. Online is needed. + order.to_invoice = true; + } + } + await super.validateOrder(isForceValidate); + }, +}); diff --git a/l10n_es_pos_oca/static/src/xml/pos.xml b/l10n_es_pos_oca/static/src/app/screens/receipt_screen/receipt/order_receipt.xml similarity index 99% rename from l10n_es_pos_oca/static/src/xml/pos.xml rename to l10n_es_pos_oca/static/src/app/screens/receipt_screen/receipt/order_receipt.xml index 0d0a2e23d13..6d42c995d42 100644 --- a/l10n_es_pos_oca/static/src/xml/pos.xml +++ b/l10n_es_pos_oca/static/src/app/screens/receipt_screen/receipt/order_receipt.xml @@ -4,7 +4,6 @@ t-name="OrderReceipt" t-inherit="point_of_sale.OrderReceipt" t-inherit-mode="extension" - owl="1" > diff --git a/l10n_es_pos_oca/static/src/app/screens/store/models.esm.js b/l10n_es_pos_oca/static/src/app/screens/store/models.esm.js new file mode 100644 index 00000000000..156a377db65 --- /dev/null +++ b/l10n_es_pos_oca/static/src/app/screens/store/models.esm.js @@ -0,0 +1,93 @@ +/** @odoo-module */ + +/* Copyright 2016 David Gómez Quilón + Copyright 2018-19 Tecnativa - David Vidal + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +*/ + +import {ConnectionLostError} from "@web/core/network/rpc_service"; +import {Order} from "@point_of_sale/app/store/models"; +import {formatDateTime} from "@web/core/l10n/dates"; +import {patch} from "@web/core/utils/patch"; + +patch(Order.prototype, { + get_total_with_tax() { + const total = super.get_total_with_tax(...arguments); + const below_limit = total <= this.pos.config.l10n_es_simplified_invoice_limit; + this.is_simplified_invoice = + below_limit && this.pos.config.is_simplified_config; + return total; + }, + set_simple_inv_number() { + return this.pos + .get_simple_inv_next_number() + .then(([config]) => { + // We'll get the number from DB only when we're online. Otherwise + // the sequence will run on the client side until the orders are + // synced. + this.pos._set_simplified_invoice_number(config); + }) + .catch((error) => { + // We'll only consider network errors + if (!ConnectionLostError(error)) { + throw error; + } + }) + .finally(() => { + const simplified_invoice_number = + this.pos._get_simplified_invoice_number(); + this.l10n_es_unique_id = simplified_invoice_number; + this.is_simplified_invoice = true; + }); + }, + get_base_by_tax() { + const base_by_tax = {}; + this.get_orderlines().forEach(function (line) { + const tax_detail = line.get_tax_details(); + const base_price = line.get_price_without_tax(); + if (tax_detail) { + Object.keys(tax_detail).forEach(function (tax) { + if (Object.keys(base_by_tax).includes(tax)) { + base_by_tax[tax] += base_price; + } else { + base_by_tax[tax] = base_price; + } + }); + } + }); + return base_by_tax; + }, + init_from_JSON(json) { + super.init_from_JSON(...arguments); + this.to_invoice = json.to_invoice; + this.l10n_es_unique_id = json.l10n_es_unique_id; + this.formatted_validation_date = formatDateTime( + moment(this.validation_date), + {}, + {timezone: false} + ); + }, + export_as_JSON() { + const res = super.export_as_JSON(...arguments); + res.to_invoice = this.is_to_invoice(); + if (!res.to_invoice) { + res.l10n_es_unique_id = this.l10n_es_unique_id; + } + return res; + }, + export_for_printing() { + const result = super.export_for_printing(...arguments); + const company = this.pos.company; + result.l10n_es_unique_id = this.l10n_es_unique_id; + result.to_invoice = this.to_invoice; + result.company.street = company.street; + result.company.zip = company.zip; + result.company.city = company.city; + result.company.state_id = company.state_id; + const base_by_tax = this.get_base_by_tax(); + for (const tax of result.tax_details) { + tax.base = base_by_tax[tax.tax.id]; + } + return result; + }, +}); diff --git a/l10n_es_pos_oca/static/src/xml/Screens/OrderManagementScreen/TicketScreen.xml b/l10n_es_pos_oca/static/src/app/screens/ticket_screen/ticket_screen.xml similarity index 97% rename from l10n_es_pos_oca/static/src/xml/Screens/OrderManagementScreen/TicketScreen.xml rename to l10n_es_pos_oca/static/src/app/screens/ticket_screen/ticket_screen.xml index aede32d3455..7350c4e8a55 100644 --- a/l10n_es_pos_oca/static/src/xml/Screens/OrderManagementScreen/TicketScreen.xml +++ b/l10n_es_pos_oca/static/src/app/screens/ticket_screen/ticket_screen.xml @@ -5,7 +5,6 @@ t-name="TicketScreen" t-inherit="point_of_sale.TicketScreen" t-inherit-mode="extension" - owl="1" >
    Simplified Invoice
    diff --git a/l10n_es_pos_oca/static/src/app/screens/ticket_screen/ticket_sreen.esm.js b/l10n_es_pos_oca/static/src/app/screens/ticket_screen/ticket_sreen.esm.js new file mode 100644 index 00000000000..4295f97d6a7 --- /dev/null +++ b/l10n_es_pos_oca/static/src/app/screens/ticket_screen/ticket_sreen.esm.js @@ -0,0 +1,17 @@ +/** @odoo-module */ + +import {TicketScreen} from "@point_of_sale/app/screens/ticket_screen/ticket_screen"; +import {_t} from "@web/core/l10n/translation"; +import {patch} from "@web/core/utils/patch"; + +patch(TicketScreen.prototype, { + _getSearchFields() { + const fields = super._getSearchFields(); + fields.SIMPLIFIED_INVOICE = { + repr: (order) => order.name, + displayName: _t("Simplified Invoice"), + modelField: "l10n_es_unique_id", + }; + return fields; + }, +}); diff --git a/l10n_es_pos_oca/static/src/js/PaymentScreen.js b/l10n_es_pos_oca/static/src/js/PaymentScreen.js deleted file mode 100644 index f48fabad54d..00000000000 --- a/l10n_es_pos_oca/static/src/js/PaymentScreen.js +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright 2016 David Gómez Quilón - Copyright 2018 Tecnativa - David Vidal - Copyright 2020 Tecnativa - João Marques - License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -*/ - -odoo.define("l10n_es_pos.PaymentScreen", function (require) { - "use strict"; - - const PaymentScreen = require("point_of_sale.PaymentScreen"); - const Registries = require("point_of_sale.Registries"); - - // eslint-disable-next-line no-shadow - const L10nEsPosPaymentScreen = (PaymentScreen) => - class extends PaymentScreen { - async validateOrder(isForceValidate) { - const below_limit = - this.currentOrder.get_total_with_tax() <= - this.env.pos.config.l10n_es_simplified_invoice_limit; - if (this.env.pos.config.is_simplified_config) { - const order = this.currentOrder; - if (below_limit && !order.to_invoice) { - await order.set_simple_inv_number(); - } else { - // Force invoice above limit. Online is needed. - order.to_invoice = true; - } - } - await super.validateOrder(isForceValidate); - } - }; - - Registries.Component.extend(PaymentScreen, L10nEsPosPaymentScreen); - - return PaymentScreen; -}); diff --git a/l10n_es_pos_oca/static/src/js/Screens/TicketScreen/TicketScreen.js b/l10n_es_pos_oca/static/src/js/Screens/TicketScreen/TicketScreen.js deleted file mode 100644 index 7909742459a..00000000000 --- a/l10n_es_pos_oca/static/src/js/Screens/TicketScreen/TicketScreen.js +++ /dev/null @@ -1,21 +0,0 @@ -odoo.define("l10n_es_pos.TicketScreen", function (require) { - "use strict"; - - const TicketScreen = require("point_of_sale.TicketScreen"); - const Registries = require("point_of_sale.Registries"); - - const L10nEsPosTicketScreen = (TicketScreen) => - class extends TicketScreen { - _getSearchFields() { - const fields = super._getSearchFields(); - fields.SIMPLIFIED_INVOICE = { - repr: (order) => order.name, - displayName: this.env._t("Simplified Invoice"), - modelField: "l10n_es_unique_id", - }; - return fields; - } - }; - Registries.Component.extend(TicketScreen, L10nEsPosTicketScreen); - return TicketScreen; -}); diff --git a/l10n_es_pos_oca/static/src/js/models.js b/l10n_es_pos_oca/static/src/js/models.js deleted file mode 100644 index d4113bda593..00000000000 --- a/l10n_es_pos_oca/static/src/js/models.js +++ /dev/null @@ -1,172 +0,0 @@ -/* Copyright 2016 David Gómez Quilón - Copyright 2018-19 Tecnativa - David Vidal - License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -*/ - -odoo.define("l10n_es_pos.models", function (require) { - "use strict"; - - const {PosGlobalState, Order} = require("point_of_sale.models"); - const Registries = require("point_of_sale.Registries"); - const {isConnectionError} = require("point_of_sale.utils"); - const {ConnectionLostError} = require("@web/core/network/rpc_service"); - const field_utils = require("web.field_utils"); - - const L10NESGlobalState = (PosGlobalState) => - class L10NESGlobalState extends PosGlobalState { - constructor() { - super(...arguments); - this.pushed_simple_invoices = []; - // Unique UUID - this.own_simplified_invoice_prefix = ""; - } - get_simple_inv_next_number() { - // If we had pending orders to sync we want to avoid getting the next number - // from the DB as we'd be ovelaping the sequence. - if (this.env.pos.db.get_orders().length) { - return Promise.reject(new ConnectionLostError()); - } - return this.env.services.rpc({ - method: "search_read", - domain: [["id", "=", this.env.pos.config.id]], - fields: ["l10n_es_simplified_invoice_number"], - model: "pos.config", - }); - } - get_padding_simple_inv(number, padding) { - var diff = padding - number.toString().length; - let result = ""; - if (diff <= 0) { - result = number; - } else { - for (let i = 0; i < diff; i++) { - result += "0"; - } - result += number; - } - return result; - } - _update_sequence_number() { - ++this.config.l10n_es_simplified_invoice_number; - } - push_simple_invoice(order) { - if ( - this.pushed_simple_invoices.indexOf( - order.data.l10n_es_unique_id - ) === -1 - ) { - this.pushed_simple_invoices.push(order.data.l10n_es_unique_id); - this._update_sequence_number(); - } - } - _flush_orders(orders) { - var self = this; - // Save pushed orders numbers - _.each(orders, function (order) { - if (!order.data.to_invoice) { - self.push_simple_invoice(order); - } - }); - return super._flush_orders(...arguments); - } - _set_simplified_invoice_number(config) { - this.config.l10n_es_simplified_invoice_number = - config.l10n_es_simplified_invoice_number; - } - _get_simplified_invoice_number() { - return ( - this.config.l10n_es_simplified_invoice_prefix + - this.get_padding_simple_inv( - this.config.l10n_es_simplified_invoice_number, - this.config.l10n_es_simplified_invoice_padding - ) - ); - } - }; - Registries.Model.extend(PosGlobalState, L10NESGlobalState); - - const L10NESOrder = (Order) => - class L10NESOrder extends Order { - get_total_with_tax() { - const total = super.get_total_with_tax(...arguments); - const below_limit = - total <= this.pos.config.l10n_es_simplified_invoice_limit; - this.is_simplified_invoice = - below_limit && this.pos.config.is_simplified_config; - return total; - } - set_simple_inv_number() { - return this.pos - .get_simple_inv_next_number() - .then(([config]) => { - // We'll get the number from DB only when we're online. Otherwise - // the sequence will run on the client side until the orders are - // synced. - this.pos._set_simplified_invoice_number(config); - }) - .catch((error) => { - // We'll only consider network errors - if (!isConnectionError(error)) { - throw error; - } - }) - .finally(() => { - const simplified_invoice_number = - this.pos._get_simplified_invoice_number(); - this.l10n_es_unique_id = simplified_invoice_number; - this.is_simplified_invoice = true; - }); - } - get_base_by_tax() { - const base_by_tax = {}; - this.get_orderlines().forEach(function (line) { - const tax_detail = line.get_tax_details(); - const base_price = line.get_price_without_tax(); - if (tax_detail) { - Object.keys(tax_detail).forEach(function (tax) { - if (Object.keys(base_by_tax).includes(tax)) { - base_by_tax[tax] += base_price; - } else { - base_by_tax[tax] = base_price; - } - }); - } - }); - return base_by_tax; - } - init_from_JSON(json) { - super.init_from_JSON(...arguments); - this.to_invoice = json.to_invoice; - this.l10n_es_unique_id = json.l10n_es_unique_id; - this.formatted_validation_date = field_utils.format.datetime( - moment(this.validation_date), - {}, - {timezone: false} - ); - } - export_as_JSON() { - const res = super.export_as_JSON(...arguments); - res.to_invoice = this.is_to_invoice(); - if (!res.to_invoice) { - res.l10n_es_unique_id = this.l10n_es_unique_id; - } - return res; - } - export_for_printing() { - const result = super.export_for_printing(...arguments); - const company = this.pos.company; - result.l10n_es_unique_id = this.l10n_es_unique_id; - result.to_invoice = this.to_invoice; - result.company.street = company.street; - result.company.zip = company.zip; - result.company.city = company.city; - result.company.state_id = company.state_id; - const base_by_tax = this.get_base_by_tax(); - for (const tax of result.tax_details) { - tax.base = base_by_tax[tax.tax.id]; - } - return result; - } - }; - Registries.Model.extend(Order, L10NESOrder); -}); diff --git a/l10n_es_pos_oca/views/res_config_settings_views.xml b/l10n_es_pos_oca/views/res_config_settings_views.xml index 5819a00a56b..ca4f204f232 100644 --- a/l10n_es_pos_oca/views/res_config_settings_views.xml +++ b/l10n_es_pos_oca/views/res_config_settings_views.xml @@ -5,16 +5,13 @@ res.config.settings - -
    -
    + + -
    -
    -
    -
    -
    + + -
    -
    + {'required': ['|', ('pos_company_has_template', '=', True), ('pos_l10n_es_simplified_invoice_sequence_id', '=', True)]} + name="required" + >pos_company_has_template or pos_l10n_es_simplified_invoice_sequence_id