Skip to content

Commit

Permalink
[MIG] l10n_es_pos_oca: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
peluko00 committed Sep 30, 2024
1 parent 6710ff5 commit d0d4432
Show file tree
Hide file tree
Showing 18 changed files with 328 additions and 343 deletions.
4 changes: 4 additions & 0 deletions l10n_es_pos_oca/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ Contributors

- Daniel Duque <daniel.duque@factorlibre.com>

- `APSL-Nagarro <https://www.apsl.tech>`__:

- Antoni Marroig <amarroig@apsl.net>

Maintainers
-----------

Expand Down
12 changes: 4 additions & 8 deletions l10n_es_pos_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-spain",
"license": "AGPL-3",
"version": "16.0.1.0.2",
"depends": ["point_of_sale"],
"version": "17.0.1.0.0",
"depends": ["point_of_sale", "l10n_es"],
"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",
"point_of_sale._assets_pos": [
"l10n_es_pos_oca/static/src/**/*",
],
},
"installable": True,
Expand Down
8 changes: 2 additions & 6 deletions l10n_es_pos_oca/hooks.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# Copyright 2018 David Vidal <david.vidal@tecnativa.com>
# 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)]
Expand Down Expand Up @@ -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()
13 changes: 9 additions & 4 deletions l10n_es_pos_oca/models/pos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -42,25 +41,31 @@ 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",
)
simplified_partner_id = fields.Many2one(
comodel_name="res.partner",
string="Simplified invoice partner",
compute="_compute_simplified_partner_id",
)

@api.depends("iface_l10n_es_simplified_invoice")
def _compute_simplified_config(self):
for pos in self:
pos.is_simplified_config = pos.iface_l10n_es_simplified_invoice

def _compute_simplified_partner_id(self):
for config in self:
config.simplified_partner_id = self.env.ref("l10n_es.partner_simplified").id

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
Expand Down
2 changes: 2 additions & 0 deletions l10n_es_pos_oca/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
- Manuel Regidor
- [Factor Libre](https://factorlibre.com/):
- Daniel Duque \<<daniel.duque@factorlibre.com>\>
- [APSL-Nagarro](https://www.apsl.tech):
- Antoni Marroig \<<amarroig@apsl.net>\>
15 changes: 11 additions & 4 deletions l10n_es_pos_oca/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -484,12 +485,18 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<li>Daniel Duque &lt;<a class="reference external" href="mailto:daniel.duque&#64;factorlibre.com">daniel.duque&#64;factorlibre.com</a>&gt;</li>
</ul>
</li>
<li><a class="reference external" href="https://www.apsl.tech">APSL-Nagarro</a>:<ul>
<li>Antoni Marroig &lt;<a class="reference external" href="mailto:amarroig&#64;apsl.net">amarroig&#64;apsl.net</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/** @odoo-module */

/* Copyright 2016 David Gómez Quilón <david.gomez@aselcis.com>
Copyright 2018 Tecnativa - David Vidal
Copyright 2020 Tecnativa - João Marques
Copyright 2024 (APSL-Nagarro) - Antoni Marroig
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.pos.config.l10n_es_simplified_invoice_limit;
if (this.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;
}
order.partner =
order.partner ||
this.pos.db.partner_by_id[this.pos.config.simplified_partner_id[0]];
}
await super.validateOrder(isForceValidate);
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates id="template" xml:space="preserve">
<t
t-name="OrderReceipt"
t-inherit="point_of_sale.OrderReceipt"
t-inherit-mode="extension"
>
<xpath expr="//div[hasclass('pos-receipt-order-data')]" position="attributes">
<attribute
name="t-if"
>!env.pos.config.is_simplified_config or props.data.is_to_invoice</attribute>
</xpath>
</t>
</templates>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates id="template" xml:space="preserve">
<t
t-name="OrderReceipt"
t-inherit="point_of_sale.ReceiptHeader"
t-inherit-mode="extension"
>
<xpath expr="//div[hasclass('pos-receipt-contact')]/div" position="before">
<t t-if="props.data.is_simplified_config and !props.data.to_invoice">
<div>Simplified invoice</div>
<div class="simplified-invoice-number" t-esc="props.data.l10n_es_unique_id" />
</t>
<div t-if="props.data.company.street" t-esc="props.data.company.street" />
<div t-if="props.data.company.zip" t-esc="props.data.company.zip" />
<div t-if="props.data.company.city" t-esc="props.data.company.city" />
<div t-if="props.data.company.state_id">(<t t-esc="props.data.company.state_id[1]"/>)</div>
</xpath>
<xpath expr="//div[hasclass('pos-receipt-contact')]" position="inside">
<t t-set="partner" t-value="props.data.partner"/>
<t t-if="partner and partner.id !== props.data.simplified_partner_id">
<div>Customer: <t t-esc="partner.name" /></div>
<div t-if="partner.vat"><t t-esc="props.data.company.country?.vat_label || 'Tax ID'"/>: <t t-esc="partner.vat" /></div>
<div t-if="partner.address" t-esc="partner.address"/>
</t>
</xpath>
</t>
</templates>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/** @odoo-module */

/* Copyright 2016 David Gómez Quilón <david.gomez@aselcis.com>
Copyright 2018-19 Tecnativa - David Vidal
Copyright 2024 (APSL-Nagarro) - Antoni Marroig
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
*/

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;
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
t-name="TicketScreen"
t-inherit="point_of_sale.TicketScreen"
t-inherit-mode="extension"
owl="1"
>
<xpath expr="//div[hasclass('header-row')]/div[2]" position="after">
<div class="col wide">Simplified Invoice</div>
Expand Down
83 changes: 83 additions & 0 deletions l10n_es_pos_oca/static/src/app/store/models.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/** @odoo-module */

/* Copyright 2016 David Gómez Quilón <david.gomez@aselcis.com>
Copyright 2018-19 Tecnativa - David Vidal
Copyright 2024 (APSL-Nagarro) - Antoni Marroig
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 {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 (!error instanceof ConnectionLostError) {
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;
},
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);
result.l10n_es_unique_id = this.l10n_es_unique_id;
result.to_invoice = this.to_invoice;
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;
},
});
Loading

0 comments on commit d0d4432

Please sign in to comment.