Skip to content

Commit

Permalink
Merge pull request #1120 from Tecnativa/12.0-fix-l10n_es_pos
Browse files Browse the repository at this point in the history
[FIX] l10n_es_pos: prevent duplicate or missing orders
  • Loading branch information
pedrobaeza committed Jun 10, 2019
2 parents 1af4ad1 + d27b4fd commit 955d7bc
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 26 deletions.
2 changes: 1 addition & 1 deletion l10n_es_pos/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-spain",
"license": "AGPL-3",
"version": "12.0.1.0.1",
"version": "12.0.2.0.0",
"depends": [
"point_of_sale",
],
Expand Down
49 changes: 28 additions & 21 deletions l10n_es_pos/i18n/es.po
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * l10n_es_pos
# * l10n_es_pos
#
msgid ""
msgstr ""
Expand Down Expand Up @@ -166,24 +166,39 @@ msgstr "Facturas simplificadas"
#: code:addons/l10n_es_pos/static/src/xml/pos.xml:43
#, python-format
msgid "Subt"
msgstr "Subtotal"
msgstr "Subt"

#. module: l10n_es_pos
#. openerp-web
#: code:addons/l10n_es_pos/static/src/js/screens.js:32
#, python-format
msgid "The current order is already queued and thus it shouldn't be changed. Click on 'Validate' in order to finalize it."
msgstr "Este pedido ya está en cola, de modo que no debería modificarse. Pulsa en 'Validar' para finalizarlo."

#. module: l10n_es_pos
#. openerp-web
#: code:addons/l10n_es_pos/static/src/js/screens.js:31
#, python-format
msgid "The order is already queued"
msgstr "El pedido ya está en cola"

#. module: l10n_es_pos
#: code:addons/l10n_es_pos/models/ir_sequence.py:20
#, python-format
msgid ""
"There is already a simplified invoice sequence with that prefix and it "
"should be unique."
msgstr ""
"Ya existe una secuencia de Factura Simplificada con ese prefijo y este "
"debería ser único."
msgid "There is already a simplified invoice sequence with that prefix and it should be unique."
msgstr "Ya existe una secuencia de Factura Simplificada con ese prefijo y este debería ser único."

#. module: l10n_es_pos
#: model:ir.model.fields,field_description:l10n_es_pos.field_pos_order_l10n_es_unique_id
msgid "Unique Order ID"
msgstr "ID único de pedido"

#. module: l10n_es_pos
#. openerp-web
#: code:addons/l10n_es_pos/static/src/xml/pos.xml:42
#, python-format
msgid "Unit"
msgstr "Unidad"
msgstr "Ud."

#. module: l10n_es_pos
#: model:ir.model.fields,field_description:l10n_es_pos.field_pos_config__iface_l10n_es_simplified_invoice
Expand All @@ -207,15 +222,7 @@ msgstr "NIF/CIF:"
msgid "on"
msgstr "sobre"

#~ msgid "pos.config"
#~ msgstr "pos.config"

#~ msgid ""
#~ "There's already another POS config using the same Simplified Invoice "
#~ "prefix. Try choosing another POS Name"
#~ msgstr ""
#~ "Ya existe otro TPV utilizando el mismo prefijo de Factura Simplifica. "
#~ "Escoge otro nombre de Punto de Venta"

#~ msgid "You need to define a simplified invoice prefix."
#~ msgstr "Debes definir un prefijo de Factura Simplificada."
#. module: l10n_es_pos
#: model:ir.model,name:l10n_es_pos.model_pos_config
msgid "pos.config"
msgstr "pos.config"
21 changes: 21 additions & 0 deletions l10n_es_pos/i18n/l10n_es_pos.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-04-23 08:57+0000\n"
"PO-Revision-Date: 2019-04-23 08:57+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -164,12 +166,31 @@ msgstr ""
msgid "Subt"
msgstr ""

#. module: l10n_es_pos
#. openerp-web
#: code:addons/l10n_es_pos/static/src/js/screens.js:32
#, python-format
msgid "The current order is already queued and thus it shouldn't be changed. Click on 'Validate' in order to finalize it."
msgstr ""

#. module: l10n_es_pos
#. openerp-web
#: code:addons/l10n_es_pos/static/src/js/screens.js:31
#, python-format
msgid "The order is already queued"
msgstr ""

#. module: l10n_es_pos
#: code:addons/l10n_es_pos/models/ir_sequence.py:20
#, python-format
msgid "There is already a simplified invoice sequence with that prefix and it should be unique."
msgstr ""

#. module: l10n_es_pos
#: model:ir.model.fields,field_description:l10n_es_pos.field_pos_order_l10n_es_unique_id
msgid "Unique Order ID"
msgstr ""

#. module: l10n_es_pos
#. openerp-web
#: code:addons/l10n_es_pos/static/src/xml/pos.xml:42
Expand Down
32 changes: 32 additions & 0 deletions l10n_es_pos/models/pos_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class PosOrder(models.Model):
copy=False,
default=False,
)
l10n_es_unique_id = fields.Char(
'Unique Order ID',
copy=False,
)

@api.model
def _simplified_limit_check(self, amount_total, limit=3000):
Expand All @@ -30,6 +34,9 @@ def _order_fields(self, ui_order):
'pos_reference': ui_order['simplified_invoice'],
'is_l10n_es_simplified_invoice': True,
})
res.update({
'l10n_es_unique_id': ui_order['uid'],
})
return res

@api.model
Expand All @@ -49,3 +56,28 @@ def _process_order(self, pos_order):
})
pos.l10n_es_simplified_invoice_sequence_id.next_by_id()
return super(PosOrder, self)._process_order(pos_order)

@api.model
def create_from_ui(self, orders):
"""Provide a context with the current session id"""
if not orders:
return super().create_from_ui(orders)
# We take the uid from every order in the sync queue to discard only
# those orders that are really unique
# TODO: Duplicated simp. invoice ids shouldn't happen but in certain
# circumstances it can ocurr, so we choose to save them anyway.
submitted_uids = [o['data']['uid'] for o in orders]
self_ctx = self.with_context(l10n_es_pos_submitted_uids=submitted_uids)
return super(PosOrder, self_ctx).create_from_ui(orders)

@api.model
def search(self, args, offset=0, limit=0, order=None, count=False):
"""If the context provided from create_from_ui() is given, we add
the unique_uid to the domain filter. This way, we prevent missing
orders if a sequence is reset. If they belong to another session
we grant them for valid despite the duped sequence number"""
submitted_uids = self.env.context.get('l10n_es_pos_submitted_uids')
if submitted_uids:
args += [('l10n_es_unique_id', 'in', submitted_uids)]
return super().search(args, offset=offset, limit=limit,
order=order, count=count)
8 changes: 5 additions & 3 deletions l10n_es_pos/static/src/js/models.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* 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).
*/

Expand All @@ -7,7 +8,6 @@ odoo.define('l10n_es_pos.models', function (require) {

var models = require('point_of_sale.models');


var pos_super = models.PosModel.prototype;
models.PosModel = models.PosModel.extend({
initialize: function (attributes, options) {
Expand Down Expand Up @@ -56,8 +56,10 @@ odoo.define('l10n_es_pos.models', function (require) {
models.Order = models.Order.extend({
get_total_with_tax: function () {
var total = order_super.get_total_with_tax.apply(this, arguments);
var below_limit = total <= this.pos.config.l10n_es_simplified_invoice_limit;
this.is_simplified_invoice = below_limit && this.pos.config.iface_l10n_es_simplified_invoice;
var below_limit = total <=
this.pos.config.l10n_es_simplified_invoice_limit;
this.is_simplified_invoice =
below_limit && this.pos.config.iface_l10n_es_simplified_invoice;
return total;
},
set_simple_inv_number: function () {
Expand Down
6 changes: 5 additions & 1 deletion l10n_es_pos/static/src/js/screens.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ odoo.define('l10n_es_pos.screens', function (require) {


screens.PaymentScreenWidget.include({
// When the order total is above the simplified invoice limit, wich
// will be the legal one on each case, it's mandatory to force the
// invoice in any case.
validate_order: function (force_validate) {
var below_limit = this.pos.get_order().get_total_with_tax() <= this.pos.config.l10n_es_simplified_invoice_limit;
var below_limit = this.pos.get_order().get_total_with_tax() <=
this.pos.config.l10n_es_simplified_invoice_limit;
if (this.pos.config.iface_l10n_es_simplified_invoice) {
var order = this.pos.get_order();
if (below_limit && !order.to_invoice) {
Expand Down

0 comments on commit 955d7bc

Please sign in to comment.