Skip to content

Commit

Permalink
[MIG] l10n_es_ticketbai_pos: Migration to 16
Browse files Browse the repository at this point in the history
  • Loading branch information
rrebollo committed Feb 4, 2025
1 parent 4d2da54 commit f45eb90
Show file tree
Hide file tree
Showing 22 changed files with 745 additions and 897 deletions.
3 changes: 2 additions & 1 deletion l10n_es_ticketbai_pos/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Installation

Para instalar éste módulo necesita:

#. Los módulos l10n_es_pos, pos_order_mgmt y l10n_es_ticketbai.
#. Los módulos l10n_es_pos y l10n_es_ticketbai.


Usage
Expand Down Expand Up @@ -67,6 +67,7 @@ Contributors
* Luis J. Salvatierra <[email protected]>
* Miquel Alzanillas <[email protected]>
* Adrián Cifuentes <[email protected]>
* Rolando Pérez <[email protected]>

Maintainers
~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion l10n_es_ticketbai_pos/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import models
from . import models, wizard
27 changes: 15 additions & 12 deletions l10n_es_ticketbai_pos/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "TicketBAI - Point of Sale - "
"declaración de todas las operaciones de venta realizadas por las personas "
"y entidades que desarrollan actividades económicas",
"version": "15.0.1.0.6",
"name": (
"TicketBAI - Point of Sale - "
"declaración de todas las operaciones de venta realizadas por las personas "
"y entidades que desarrollan actividades económicas"
),
"version": "16.0.1.0.0",
"category": "Accounting & Finance",
"website": "https://github.com/OCA/l10n-spain",
"author": "Binovo," "Odoo Community Association (OCA)",
"author": "Binovo,Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
Expand All @@ -19,23 +21,24 @@
"depends": ["l10n_es_pos", "l10n_es_ticketbai"],
"data": [
"security/ir.model.access.csv",
"views/l10n_es_ticketbai_pos_views.xml",
"views/pos_order_views.xml",
"views/ticketbai_certificate_views.xml",
"wizard/res_config_settings_views.xml",
],
"assets": {
"web.assets_qweb": [
"l10n_es_ticketbai_pos/static/src/xml/pos.xml",
],
"point_of_sale.assets": [
"l10n_es_ticketbai_pos/static/src/xml/pos.xml",
"l10n_es_ticketbai_pos/static/lib/qrcode.js",
"l10n_es_ticketbai_pos/static/lib/tbai.js",
"l10n_es_ticketbai_pos/static/src/js/models.js",
"l10n_es_ticketbai_pos/static/src/js/tbai_models.js",
"l10n_es_ticketbai_pos/static/src/js/db.js",
"l10n_es_ticketbai_pos/static/src/js/Screens/ClientListScreen/ClientListScreen.js",
"l10n_es_ticketbai_pos/static/src/js/Screens/PaymentScreen/PaymentScreen.js",
"l10n_es_ticketbai_pos/static/src/js/Screens/ProductScreen/ProductScreen.js",
"l10n_es_ticketbai_pos/static/src/js/Screens/PartnerListScreen/"
"PartnerListScreen.js",
"l10n_es_ticketbai_pos/static/src/js/Screens/PaymentScreen/"
"PaymentScreen.js",
"l10n_es_ticketbai_pos/static/src/js/Screens/ProductScreen/"
"ProductScreen.js",
],
},
}
1 change: 1 addition & 0 deletions l10n_es_ticketbai_pos/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import account_move
from . import pos_config
from . import pos_session
from . import pos_order
from . import ticketbai_invoice
28 changes: 8 additions & 20 deletions l10n_es_ticketbai_pos/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright 2022 Landoo Sistemas de Informacion SL
# Copyright 2022 Advanced Programming Solutions SL
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
from odoo import Command, fields, models


class AccountMove(models.Model):
Expand All @@ -16,21 +16,13 @@ class AccountMove(models.Model):

def tbai_prepare_invoice_values(self):
res = super().tbai_prepare_invoice_values()
if not res.get("vat_regime_key", False):
res["vat_regime_key"] = (
self.env["tbai.vat.regime.key"]
.search([("code", "=", "01")], limit=1)
.code
)
if self.tbai_substitute_simplified_invoice:
refunded_pos_order = self.tbai_substitution_pos_order_id
res.update(
{
"is_invoice_refund": False,
"tbai_invoice_refund_ids": [
(
0,
0,
Command.create(
{
"number_prefix": (
refunded_pos_order.tbai_get_value_serie_factura()
Expand All @@ -41,7 +33,7 @@ def tbai_prepare_invoice_values(self):
"expedition_date": (
refunded_pos_order.tbai_get_value_fecha_expedicion_factura()
),
},
}
)
],
}
Expand All @@ -50,15 +42,11 @@ def tbai_prepare_invoice_values(self):

# For Ticketbai is mandatory to specify origin invoice in refunds
def _post(self, soft=True):
def set_reverse_entries(self):
for invoice in self:
pos_order_ids = invoice.sudo().pos_order_ids
for pos_order in pos_order_ids:
pos_refunded_orders = pos_order.refunded_order_ids
for refunded_order_id in pos_refunded_orders:
refunded_invoice_id = refunded_order_id.account_move
invoice.reversed_entry_id = refunded_invoice_id.id
for pos_order in (
self.sudo().mapped("pos_order_ids").filtered("refunded_order_ids")
):
refunded_order = pos_order.refunded_order_ids[0]
pos_order.reversed_entry_id = refunded_order.account_move.id

Check warning on line 49 in l10n_es_ticketbai_pos/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_ticketbai_pos/models/account_move.py#L48-L49

Added lines #L48 - L49 were not covered by tests

set_reverse_entries(self)
res = super()._post(soft)
return res
76 changes: 27 additions & 49 deletions l10n_es_ticketbai_pos/models/pos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import base64
import logging

from odoo import _, exceptions, fields, models
from odoo import _, api, exceptions, fields, models

_logger = logging.getLogger(__name__)


try:
from cryptography.hazmat.primitives.serialization import (
BestAvailableEncryption,
Expand All @@ -35,63 +34,42 @@ class PosConfig(models.Model):
)
iface_l10n_es_simplified_invoice = fields.Boolean(default=True)

def _get_certificate_details(self, certificate):
p12 = certificate.get_p12()
return p12[0], p12[1], certificate.name.encode("utf-8")

Check warning on line 39 in l10n_es_ticketbai_pos/models/pos_config.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_ticketbai_pos/models/pos_config.py#L38-L39

Added lines #L38 - L39 were not covered by tests

def get_tbai_p12_and_friendlyname(self):
self.ensure_one()
record = self.sudo()

Check warning on line 43 in l10n_es_ticketbai_pos/models/pos_config.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_ticketbai_pos/models/pos_config.py#L42-L43

Added lines #L42 - L43 were not covered by tests
if record.tbai_enabled:
if record.tbai_certificate_id:
# Serialize new PKCS12 unencrypted object
p12 = record.tbai_certificate_id.get_p12()
p12_priv_key = p12[0]
p12_cert = p12[1]
p12_friendlyname = record.tbai_certificate_id.name.encode("utf-8")
p12_password = record.tbai_certificate_id.password.encode()
p12_encryption = BestAvailableEncryption(p12_password)
certificate = pkcs12.serialize_key_and_certificates(
p12_friendlyname, p12_priv_key, p12_cert, None, p12_encryption
)

tbai_p12 = base64.b64encode(certificate)
tbai_p12_friendlyname = p12_friendlyname
else:
p12 = record.company_id.tbai_aeat_certificate_id.get_p12()
p12_priv_key = p12[0]
p12_cert = p12[1]
p12_friendlyname = (
record.company_id.tbai_aeat_certificate_id.name.encode("utf-8")
)
p12_encryption = NoEncryption()
p12_password = False
certificate = pkcs12.serialize_key_and_certificates(
p12_friendlyname, p12_priv_key, p12_cert, None, p12_encryption
)
tbai_p12 = base64.b64encode(certificate)
tbai_p12_friendlyname = p12_friendlyname
else:
tbai_p12 = None
tbai_p12_friendlyname = None
return tbai_p12, tbai_p12_friendlyname, p12_password

def open_ui(self):
self.ensure_one()
if self.tbai_enabled and not self.is_simplified_config:
raise exceptions.ValidationError(
_("Simplified Invoice IDs Sequence is required")
cert = (

Check warning on line 45 in l10n_es_ticketbai_pos/models/pos_config.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_ticketbai_pos/models/pos_config.py#L45

Added line #L45 was not covered by tests
record.tbai_certificate_id or record.company_id.tbai_aeat_certificate_id
)
p12_priv_key, p12_cert, p12_friendlyname = self._get_certificate_details(

Check warning on line 48 in l10n_es_ticketbai_pos/models/pos_config.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_ticketbai_pos/models/pos_config.py#L48

Added line #L48 was not covered by tests
cert
)
return super().open_ui()
p12_password = (

Check warning on line 51 in l10n_es_ticketbai_pos/models/pos_config.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_ticketbai_pos/models/pos_config.py#L51

Added line #L51 was not covered by tests
cert.password.encode() if cert == record.tbai_certificate_id else False
)
p12_encryption = (

Check warning on line 54 in l10n_es_ticketbai_pos/models/pos_config.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_ticketbai_pos/models/pos_config.py#L54

Added line #L54 was not covered by tests
BestAvailableEncryption(p12_password)
if p12_password
else NoEncryption()
)
certificate = pkcs12.serialize_key_and_certificates(

Check warning on line 59 in l10n_es_ticketbai_pos/models/pos_config.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_ticketbai_pos/models/pos_config.py#L59

Added line #L59 was not covered by tests
p12_friendlyname, p12_priv_key, p12_cert, None, p12_encryption
)
return base64.b64encode(certificate), p12_friendlyname, p12_password
return None, None, None

Check warning on line 63 in l10n_es_ticketbai_pos/models/pos_config.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_ticketbai_pos/models/pos_config.py#L62-L63

Added lines #L62 - L63 were not covered by tests

def open_session_cb(self, check_coa=True):
self.ensure_one()
if self.tbai_enabled and not self.is_simplified_config:
@api.constrains("iface_l10n_es_simplified_invoice")
def _check_tbai(self):
if self.tbai_enabled and not self.iface_l10n_es_simplified_invoice:
raise exceptions.ValidationError(
_("Simplified Invoice IDs Sequence is required")
)
return super().open_session_cb(check_coa=check_coa)

def open_existing_session_cb(self):
self.ensure_one()
if self.tbai_enabled and not self.is_simplified_config:
raise exceptions.ValidationError(
_("Simplified Invoice IDs Sequence is required")
)
self._check_tbai()
return super().open_existing_session_cb()
Loading

0 comments on commit f45eb90

Please sign in to comment.