Skip to content

Commit 3d60a10

Browse files
committed
[T-9158][ADD] l10n_es_genci_stock_picking_report_value
1 parent 2cce8af commit 3d60a10

15 files changed

Lines changed: 850 additions & 0 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
.. image:: https://odoo-community.org/readme-banner-image
2+
:target: https://odoo-community.org/get-involved?utm_source=readme
3+
:alt: Odoo Community Association
4+
5+
===========================
6+
GENCI Report Picking Valued
7+
===========================
8+
9+
..
10+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
11+
!! This file is generated by oca-gen-addon-readme !!
12+
!! changes will be overwritten. !!
13+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14+
!! source digest: sha256:74cf46b9ce236253653a314c1f7a8cf85258c3132ec3ea976205e15b67428451
15+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16+
17+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
18+
:target: https://odoo-community.org/page/development-status
19+
:alt: Beta
20+
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
21+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
22+
:alt: License: AGPL-3
23+
.. |badge3| image:: https://img.shields.io/badge/github-sygel--technology%2Fsy--l10n--spain-lightgray.png?logo=github
24+
:target: https://github.com/sygel-technology/sy-l10n-spain/tree/16.0/l10n_es_genci_stock_picking_report_value
25+
:alt: sygel-technology/sy-l10n-spain
26+
27+
|badge1| |badge2| |badge3|
28+
29+
30+
31+
**Table of contents**
32+
33+
.. contents::
34+
:local:
35+
36+
Installation
37+
============
38+
39+
To install this module, you need to:
40+
41+
- Only install
42+
43+
Usage
44+
=====
45+
46+
47+
48+
Bug Tracker
49+
===========
50+
51+
Bugs are tracked on `GitHub Issues <https://github.com/sygel-technology/sy-l10n-spain/issues>`_.
52+
In case of trouble, please check there if your issue has already been reported.
53+
If you spotted it first, help us to smash it by providing a detailed and welcomed
54+
`feedback <https://github.com/sygel-technology/sy-l10n-spain/issues/new?body=module:%20l10n_es_genci_stock_picking_report_value%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
55+
56+
Do not contact contributors directly about support or help with technical issues.
57+
58+
Credits
59+
=======
60+
61+
Authors
62+
-------
63+
64+
* Sygel
65+
66+
Contributors
67+
------------
68+
69+
- `Sygel <https://www.sygel.es>`__:
70+
71+
- Ángel Rivas
72+
- Valentín Vinagre
73+
74+
Maintainers
75+
-----------
76+
77+
This module is part of the `sygel-technology/sy-l10n-spain <https://github.com/sygel-technology/sy-l10n-spain/tree/16.0/l10n_es_genci_stock_picking_report_value>`_ project on GitHub.
78+
79+
You are welcome to contribute.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright 2025 Ángel Rivas <angel.rivas@sygel.es>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from . import models
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2025 Ángel Rivas <angel.rivas@sygel.es>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "GENCI Report Picking Valued",
6+
"summary": "Show GENCI amount in valued stock pickings",
7+
"version": "16.0.1.0.0",
8+
"license": "AGPL-3",
9+
"author": "Sygel",
10+
"website": "https://github.com/sygel-technology/sy-l10n-spain",
11+
"category": "Accounting",
12+
"depends": [
13+
"stock_picking_report_valued",
14+
"l10n_es_genci_sale",
15+
],
16+
"data": [
17+
"report/stock_picking_report_valued_template.xml",
18+
],
19+
"installable": True,
20+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright 2025 Ángel Rivas <angel.rivas@sygel.es>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from . import stock_picking
5+
from . import stock_move_line
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Copyright 2025 Ángel Rivas <angel.rivas@sygel.es>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, fields, models
5+
6+
7+
class StockMoveLine(models.Model):
8+
_inherit = "stock.move.line"
9+
10+
genci_amount_subtotal = fields.Monetary(
11+
compute="_compute_genci_amount",
12+
compute_sudo=True,
13+
currency_field="currency_id",
14+
)
15+
genci_amount_tax = fields.Monetary(
16+
compute="_compute_genci_amount",
17+
compute_sudo=True,
18+
currency_field="currency_id",
19+
)
20+
genci_amount_total = fields.Monetary(
21+
compute="_compute_genci_amount",
22+
compute_sudo=True,
23+
currency_field="currency_id",
24+
)
25+
26+
genci_rule_id = fields.Many2one(
27+
"genci.rule",
28+
compute="_compute_genci_amount",
29+
store=False,
30+
readonly=True,
31+
)
32+
33+
def _get_genci_product_taxes(self, genci_product):
34+
"""Map GENCI product taxes through fiscal position (similar to SIGAUS)."""
35+
self.ensure_one()
36+
taxes = genci_product.taxes_id
37+
if not taxes:
38+
return False
39+
40+
sale = self.sale_line.order_id if self.sale_line else False
41+
fiscal_position = sale.fiscal_position_id if sale else False
42+
43+
return fiscal_position.map_tax(taxes) if fiscal_position else taxes
44+
45+
def _get_genci_tax_base_line_dict(self, genci_product, price, qty):
46+
"""Prepare tax base line dict for account.tax._compute_taxes()."""
47+
self.ensure_one()
48+
return self.env["account.tax"]._convert_to_tax_base_line_dict(
49+
self,
50+
partner=self.sale_line.order_partner_id,
51+
currency=self.currency_id,
52+
product=genci_product,
53+
taxes=self._get_genci_product_taxes(genci_product),
54+
price_unit=price,
55+
quantity=qty,
56+
)
57+
58+
@api.depends(
59+
"product_id",
60+
"qty_done",
61+
"reserved_qty",
62+
"sale_line",
63+
"sale_line.order_id.is_genci",
64+
"sale_line.order_id.date_order",
65+
"product_id.genci_has_amount",
66+
"product_id.genci_rule_id",
67+
)
68+
def _compute_genci_amount(self):
69+
Tax = self.env["account.tax"]
70+
71+
for line in self:
72+
# Reset default values
73+
line.genci_amount_subtotal = 0.0
74+
line.genci_amount_tax = 0.0
75+
line.genci_amount_total = 0.0
76+
line.genci_rule_id = False
77+
78+
# Minimum conditions to compute GENCI
79+
if (
80+
not line.product_id
81+
or not line.sale_line
82+
or not line.sale_line.order_id.is_genci
83+
or not line.product_id.genci_has_amount
84+
or not line.product_id.genci_rule_id
85+
):
86+
continue
87+
88+
rule = line.product_id.genci_rule_id
89+
line.genci_rule_id = rule
90+
91+
# 👉 Cantidad para GENCI: UNIDADES, no peso
92+
qty = line._get_report_valued_quantity() or line.qty_done or 0.0
93+
94+
if not qty:
95+
continue
96+
97+
price_unit = rule.unit_price
98+
99+
# GENCI service product (para impuestos / cuenta)
100+
genci_product = self.env.ref("l10n_es_genci_account.product_genci_service")
101+
102+
# Línea base para impuestos
103+
tax_base_line = line._get_genci_tax_base_line_dict(
104+
genci_product=genci_product,
105+
price=price_unit,
106+
qty=qty,
107+
)
108+
109+
tax_res = Tax._compute_taxes([tax_base_line])
110+
totals = list(tax_res["totals"].values())[0]
111+
112+
line.genci_amount_subtotal = totals.get("amount_untaxed", 0.0)
113+
line.genci_amount_tax = totals.get("amount_tax", 0.0)
114+
line.genci_amount_total = line.genci_amount_subtotal + line.genci_amount_tax
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Copyright 2025 Ángel Rivas <angel.rivas@sygel.es>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, fields, models
5+
6+
7+
class StockPicking(models.Model):
8+
_inherit = "stock.picking"
9+
10+
# Totales GENCI del picking
11+
genci_amount_subtotal = fields.Monetary(
12+
compute="_compute_genci_amounts",
13+
compute_sudo=True,
14+
currency_field="currency_id",
15+
)
16+
genci_amount_tax = fields.Monetary(
17+
compute="_compute_genci_amounts",
18+
compute_sudo=True,
19+
currency_field="currency_id",
20+
)
21+
genci_amount_total = fields.Monetary(
22+
compute="_compute_genci_amounts",
23+
compute_sudo=True,
24+
currency_field="currency_id",
25+
)
26+
27+
picking_total_with_genci = fields.Monetary(
28+
compute="_compute_genci_amounts",
29+
compute_sudo=True,
30+
currency_field="currency_id",
31+
)
32+
33+
# Importante: estructura de resumen por regla GENCI
34+
genci_rule_summary = fields.Json(
35+
compute="_compute_genci_amounts",
36+
compute_sudo=True,
37+
help="Resumen por cada regla GENCI aplicada en el albarán: "
38+
"{rule_id: {name, untaxed, tax, total}}",
39+
)
40+
41+
# -------------------------------------------------------
42+
# COMPUTE
43+
# -------------------------------------------------------
44+
@api.depends(
45+
"move_line_ids",
46+
"move_line_ids.genci_amount_subtotal",
47+
"move_line_ids.genci_amount_tax",
48+
"move_line_ids.genci_amount_total",
49+
"sale_id",
50+
"sale_id.is_genci",
51+
)
52+
def _compute_genci_amounts(self):
53+
for picking in self:
54+
55+
# Inicializar SIEMPRE para evitar CacheMiss
56+
summary = {}
57+
subtotal = 0.0
58+
tax = 0.0
59+
total = 0.0
60+
61+
# Verificar condiciones mínimas
62+
if picking.sale_id and picking.sale_id.is_genci and picking.move_line_ids:
63+
for line in picking.move_line_ids:
64+
rule = line.product_id.genci_rule_id
65+
if not rule:
66+
continue
67+
68+
rule_id = rule.id
69+
if rule_id not in summary:
70+
summary[rule_id] = {
71+
"name": rule.name,
72+
"untaxed": 0.0,
73+
"tax": 0.0,
74+
"total": 0.0,
75+
}
76+
77+
summary[rule_id]["untaxed"] += line.genci_amount_subtotal
78+
summary[rule_id]["tax"] += line.genci_amount_tax
79+
summary[rule_id]["total"] += line.genci_amount_total
80+
81+
subtotal += line.genci_amount_subtotal
82+
tax += line.genci_amount_tax
83+
total += line.genci_amount_total
84+
85+
# Asignación FINAL OBLIGATORIA
86+
picking.genci_rule_summary = summary
87+
picking.genci_amount_subtotal = subtotal
88+
picking.genci_amount_tax = tax
89+
picking.genci_amount_total = total
90+
picking.picking_total_with_genci = picking.amount_total + total
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- [Sygel](https://www.sygel.es):
2+
- Ángel Rivas
3+
- Valentín Vinagre
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
To install this module, you need to:
2+
- Only install
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)