Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][IMP] l10n_es_pos: Secuencias por dispositivo #2812

Merged
merged 3 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion l10n_es_pos/models/pos_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def _order_fields(self, ui_order):
)
return res

@api.model
def _update_sequence_number(self, pos):
pos.l10n_es_simplified_invoice_sequence_id.next_by_id()

@api.model
def _process_order(self, pos_order, draft, existing_order):
order_data = pos_order.get("data", {})
Expand All @@ -53,7 +57,7 @@ def _process_order(self, pos_order, draft, existing_order):
"is_l10n_es_simplified_invoice": True,
}
)
pos.l10n_es_simplified_invoice_sequence_id.next_by_id()
self._update_sequence_number(pos)
return super()._process_order(pos_order, draft, existing_order)

def _get_fields_for_order_line(self):
Expand Down
9 changes: 7 additions & 2 deletions l10n_es_pos/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
No se comprueba el límite en operaciones separadas para un mismo cliente, algo
que Hacienda proscribe.
* No se comprueba el límite en operaciones separadas para un mismo cliente, algo
que Hacienda proscribe.
* El soporte para usuarios concurrentes sobre una misma sesión es limitado y solo es
fiable si ambos puestos están online. En el caso de que cualquiera de ellos estuviese
offline, se correría el riesgo de solapar la secuencia de factura simplificada. Se
recomienda que en estos casos se añada mejor una configuración de punto de venta
adicional.
10 changes: 5 additions & 5 deletions l10n_es_pos/static/src/js/PaymentScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ odoo.define("l10n_es_pos.PaymentScreen", function (require) {

const L10nEsPosPaymentScreen = (PaymentScreen) =>
class extends PaymentScreen {
async validateOrder(isForceValidate) {
var below_limit =
async _finalizeValidation() {
const below_limit =
this.currentOrder.get_total_with_tax() <=
this.env.pos.config.l10n_es_simplified_invoice_limit;
if (this.env.pos.config.iface_l10n_es_simplified_invoice) {
var order = this.currentOrder;
if (this.env.pos._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;
}
}
super.validateOrder(isForceValidate);
super._finalizeValidation();
}
};

Expand Down
70 changes: 47 additions & 23 deletions l10n_es_pos/static/src/js/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@ odoo.define("l10n_es_pos.models", function (require) {
initialize: function () {
pos_super.initialize.apply(this, arguments);
this.pushed_simple_invoices = [];

this.own_simplified_invoice_prefix = ""; // Unique UUID
return this;
},
get_simple_inv_next_number: function () {
// 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({message: {code: "pending_orders"}});
}
return this.rpc({
method: "search_read",
domain: [["id", "=", this.config_id]],
fields: ["l10n_es_simplified_invoice_number"],
model: "pos.config",
});
},
get_padding_simple_inv: function (number) {
var diff =
this.config.l10n_es_simplified_invoice_padding -
number.toString().length;
get_padding_simple_inv: function (number, padding) {
var diff = padding - number.toString().length;
var result = "";
if (diff <= 0) {
result = number;
Expand All @@ -40,12 +41,15 @@ odoo.define("l10n_es_pos.models", function (require) {
}
return result;
},
_update_sequence_number: function () {
++this.config.l10n_es_simplified_invoice_number;
},
push_simple_invoice: function (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.config.l10n_es_simplified_invoice_number;
this._update_sequence_number();
}
},
_flush_orders: function (orders) {
Expand All @@ -58,6 +62,22 @@ odoo.define("l10n_es_pos.models", function (require) {
});
return pos_super._flush_orders.apply(this, arguments);
},
_is_simplified_config() {
return this.config.iface_l10n_es_simplified_invoice;
},
_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
)
);
},
});

var order_super = models.Order.prototype;
Expand All @@ -66,28 +86,32 @@ odoo.define("l10n_es_pos.models", function (require) {
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;
below_limit && this.pos._is_simplified_config();
return total;
},
set_simple_inv_number: function () {
const self = this;
return this.pos
.get_simple_inv_next_number()
.then(function (configs) {
const config = configs[0];
self.pos.config.l10n_es_simplified_invoice_number =
config.l10n_es_simplified_invoice_number;
const simplified_invoice_number =
self.pos.config.l10n_es_simplified_invoice_prefix +
self.pos.get_padding_simple_inv(
config.l10n_es_simplified_invoice_number
);
self.l10n_es_unique_id = simplified_invoice_number;
self.is_simplified_invoice = true;
.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 (XmlHttpRequestError) or
// forced rejections to resync invoice numbers
if (
error.message &&
![-32098, "pending_orders"].includes(error.message.code)
) {
throw error;
}
})
.catch(function () {
self.l10n_es_unique_id = self.uid;
self.is_simplified_invoice = true;
.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: function () {
Expand Down
121 changes: 121 additions & 0 deletions l10n_es_pos_by_device/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
=================================================================
Punto de venta adaptado a la legislación española por dispositivo
=================================================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--spain-lightgray.png?logo=github
:target: https://github.com/OCA/l10n-spain/tree/14.0/l10n_es_pos_by_device
:alt: OCA/l10n-spain
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/l10n-spain-14-0/l10n-spain-14-0-l10n_es_pos_by_device
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/l10n-spain&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

* Cubre el requerimiento legal de secuencias de facturas simplificadas del TPV
en el caso de que los dispositivos se queden sin conexión.

**Table of contents**

.. contents::
:local:

Configuration
=============

**Activación secuencia por dispositivo**

* Esta configuración se activa en *Ajustes > Punto de venta > Secuenciación*.
* Acceder a Punto de venta > Configuración > Dispositivos físicos TPV
- Crear dispositivos y sus secuencias. Cada dispositivo debe tener su
propia secuencia.
* Acceder a la configuración del punto de venta
- Establecer los dispositivos disponibles en ese punto de venta.
Si se deja en blanco, se podrán seleccionar todos los dispositivos creados.

Usage
=====

En caso de la activación de secuencias por dispositivo:

**Selección de dispositivo**

Al entrar en la sesión se establecerá el dispositivo a utilizar.

* En caso de que haya conexión, el dispositivo es bloqueado y no puede ser
seleccionado al entrar a la sesión desde otro dispositivo.

* En caso de que no haya conexión, al intentar realizar el primer pedido
el dispositivo será expulsado de la sesión. Cuando se vuelva a conectar y
entre en la sesión, el pedido estará pendiente. Se podrá acabar de tramitar.

**Transcurso de sesión**

Se irán haciendo pedidos, y se establecerá la secuencia indicada en la
definición del dispositivo.

En caso de pérdida de conexión: Cuando se recupere la conexión se incluirán los
pedidos en la sesión.

En caso de pérdida de conexión + incidente en dispositivo (pérdida de batería,
cierre de ventana o navegador): El dispositivo se queda bloqueado. Tiene que
ser desbloqueado manualmente para volver a usarse. En caso entrar en la misma
sesión, los pedidos pendientes se incluirán en la misma sesión. En caso de ser
una sesión diferente, serán incluidos en una sesión de rescate siguiendo el
estándar de Odoo.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-spain/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/l10n-spain/issues/new?body=module:%20l10n_es_pos_by_device%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Landoo Sistemas de Información S.L

Contributors
~~~~~~~~~~~~

* `Landoo <https://www.landoo.es>`_:

* Aritz Olea <[email protected]>
* Gelo Joga <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

This module is part of the `OCA/l10n-spain <https://github.com/OCA/l10n-spain/tree/14.0/l10n_es_pos_by_device>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions l10n_es_pos_by_device/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
25 changes: 25 additions & 0 deletions l10n_es_pos_by_device/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Punto de venta adaptado a la legislación española por " "dispositivo",
"category": "Sales/Point Of Sale",
"author": "Landoo Sistemas de Información S.L, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-spain",
"license": "AGPL-3",
"version": "14.0.1.0.0",
"maintainers": ["ao-landoo"],
"depends": ["l10n_es_pos"],
"data": [
"security/ir.model.access.csv",
"security/device_security.xml",
"views/pos_templates.xml",
"views/pos_views.xml",
"views/res_config_views.xml",
],
"qweb": [
"static/src/xml/pos.xml",
"static/src/xml/Screens/Chrome/Chrome.xml",
"static/src/xml/Screens/Chrome/DeviceName.xml",
],
"installable": True,
}
Loading