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 25, 2024
1 parent 6710ff5 commit 1be5de5
Show file tree
Hide file tree
Showing 15 changed files with 173 additions and 274 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: 6 additions & 6 deletions l10n_es_pos_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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()

Check warning on line 48 in l10n_es_pos_oca/hooks.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_pos_oca/hooks.py#L48

Added line #L48 was not covered by tests
4 changes: 0 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,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",
)

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>\>
4 changes: 4 additions & 0 deletions l10n_es_pos_oca/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ <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">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Copyright 2016 David Gómez Quilón <david.gomez@aselcis.com>
Copyright 2018 Tecnativa - David Vidal
Copyright 2020 Tecnativa - João Marques
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
*/

/** @odoo-module */

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);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
t-name="OrderReceipt"
t-inherit="point_of_sale.OrderReceipt"
t-inherit-mode="extension"
owl="1"
>
<xpath expr="//t[@t-if='receipt.company.contact_address']" position="before">
<t t-if="env.pos.config.is_simplified_config and !receipt.to_invoice">
Expand Down
91 changes: 91 additions & 0 deletions l10n_es_pos_oca/static/src/app/screens/store/models.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* Copyright 2016 David Gómez Quilón <david.gomez@aselcis.com>
Copyright 2018-19 Tecnativa - David Vidal
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
*/

/** @odoo-module */

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 (!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;
},
});
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @odoo-module */

import {TicketScreen} from "@point_of_sale/app/screens/ticket_screen/ticket_screen";
import {patch} from "@web/core/utils/patch";

patch(TicketScreen.prototype, {
_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;
},
});
36 changes: 0 additions & 36 deletions l10n_es_pos_oca/static/src/js/PaymentScreen.js

This file was deleted.

21 changes: 0 additions & 21 deletions l10n_es_pos_oca/static/src/js/Screens/TicketScreen/TicketScreen.js

This file was deleted.

Loading

0 comments on commit 1be5de5

Please sign in to comment.