Skip to content

Commit 1ea0e10

Browse files
author
diego.fernandez
committed
[IMP] intrastat_delivery: Añadido un orden de prioridad distinto para que establezca el incoterm en primer lugar del partner, despúes del método de envio y por último el general, si no quedará vacío.
odoo-16/fl-v16#6678
1 parent b8c632d commit 1ea0e10

6 files changed

Lines changed: 120 additions & 15 deletions

File tree

intrastat_delivery/README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ from that sales order.
4040
It is recommended to set TRUE the "Show incoterms in orders and invoices" value at
4141
"Settings / Sales".
4242

43+
Incoterm selection priority:
44+
45+
When assigning the Incoterm to a sales order, the following priority is applied:
46+
47+
1. First, the Incoterm set on the partner is used.
48+
2. If not defined, the Incoterm from the shipping method is used.
49+
3. If still not defined, the general settings Incoterm is used.
50+
4. If none of the above are set, the Incoterm field remains empty.
51+
4352
**Table of contents**
4453

4554
.. contents::
@@ -72,6 +81,7 @@ Contributors
7281
~~~~~~~~~~~~
7382

7483
* Aritz Olea <aritz.olea@factorlibre.com>
84+
* Diego Fernández <diego.fernandez@factorlibre.com>
7585

7686
Maintainers
7787
~~~~~~~~~~~

intrastat_delivery/models/sale_order.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
11
# © 2023 FactorLibre - Aritz Olea <aritz.olea@factorlibre.com>
2-
from odoo import models
2+
from odoo import api, models
33

44

55
class SaleOrder(models.Model):
66
_inherit = "sale.order"
77

8+
def _get_default_incoterm(self):
9+
"""Obtiene el Incoterm por orden de prioridad"""
10+
self.ensure_one()
11+
partner_incoterm = self.partner_id.sale_incoterm_id
12+
if partner_incoterm:
13+
return partner_incoterm
14+
carrier_incoterm = self.carrier_id.incoterm
15+
if carrier_incoterm:
16+
return carrier_incoterm
17+
company_incoterm = self.company_id.incoterm_id
18+
if company_incoterm:
19+
return company_incoterm
20+
return False
21+
22+
@api.onchange("partner_id", "carrier_id")
23+
def _onchange_partner_or_carrier(self):
24+
for order in self:
25+
order.incoterm = order._get_default_incoterm()
26+
827
def _action_confirm(self):
928
ret = super()._action_confirm()
1029
for order in self:
1130
order.write(
1231
{
13-
"incoterm": order.carrier_id.incoterm.id,
32+
"incoterm": order._get_default_incoterm().id,
1433
"intrastat_transport_id": order.carrier_id.intrastat_transport_id.id,
1534
}
1635
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
* Aritz Olea <aritz.olea@factorlibre.com>
2+
* Diego Fernández <diego.fernandez@factorlibre.com>

intrastat_delivery/readme/DESCRIPTION.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,13 @@ The mode of transport and incoterm are assigned to the sales order when it goes
88
from that sales order.
99

1010
It is recommended to set TRUE the "Show incoterms in orders and invoices" value at
11-
"Settings / Sales".
11+
"Settings / Sales".
12+
13+
Incoterm selection priority:
14+
15+
When assigning the Incoterm to a sales order, the following priority is applied:
16+
17+
1. First, the Incoterm set on the partner is used.
18+
2. If not defined, the Incoterm from the shipping method is used.
19+
3. If still not defined, the general settings Incoterm is used.
20+
4. If none of the above are set, the Incoterm field remains empty.

intrastat_delivery/static/description/index.html

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<?xml version="1.0" encoding="utf-8"?>
21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
32
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
43
<head>
@@ -9,10 +8,11 @@
98

109
/*
1110
:Author: David Goodger (goodger@python.org)
12-
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
11+
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
1312
:Copyright: This stylesheet has been placed in the public domain.
1413
1514
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1616
1717
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1818
customize this style sheet.
@@ -275,7 +275,7 @@
275275
margin-left: 2em ;
276276
margin-right: 2em }
277277

278-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
279279
pre.code, code { background-color: #eeeeee }
280280
pre.code .comment, code .comment { color: #5C6576 }
281281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -301,7 +301,7 @@
301301
span.pre {
302302
white-space: pre }
303303

304-
span.problematic {
304+
span.problematic, pre.problematic {
305305
color: red }
306306

307307
span.section-subtitle {
@@ -379,6 +379,14 @@ <h1 class="title">Propagate incoterm from sale delivery to invoice</h1>
379379
from that sales order.</p>
380380
<p>It is recommended to set TRUE the “Show incoterms in orders and invoices” value at
381381
“Settings / Sales”.</p>
382+
<p>Incoterm selection priority:</p>
383+
<p>When assigning the Incoterm to a sales order, the following priority is applied:</p>
384+
<ol class="arabic simple">
385+
<li>First, the Incoterm set on the partner is used.</li>
386+
<li>If not defined, the Incoterm from the shipping method is used.</li>
387+
<li>If still not defined, the general settings Incoterm is used.</li>
388+
<li>If none of the above are set, the Incoterm field remains empty.</li>
389+
</ol>
382390
<p><strong>Table of contents</strong></p>
383391
<div class="contents local topic" id="contents">
384392
<ul class="simple">
@@ -416,12 +424,15 @@ <h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
416424
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
417425
<ul class="simple">
418426
<li>Aritz Olea &lt;<a class="reference external" href="mailto:aritz.olea&#64;factorlibre.com">aritz.olea&#64;factorlibre.com</a>&gt;</li>
427+
<li>Diego Fernández &lt;<a class="reference external" href="mailto:diego.fernandez&#64;factorlibre.com">diego.fernandez&#64;factorlibre.com</a>&gt;</li>
419428
</ul>
420429
</div>
421430
<div class="section" id="maintainers">
422431
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
423432
<p>This module is maintained by the OCA.</p>
424-
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
433+
<a class="reference external image-reference" href="https://odoo-community.org">
434+
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
435+
</a>
425436
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
426437
mission is to support the collaborative development of Odoo features and
427438
promote its widespread use.</p>

intrastat_delivery/tests/test_intrastat_delivery.py

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ def setUpClass(cls):
2222
}
2323
)
2424
cls.incoterm = cls.env["account.incoterms"].create(
25-
{"name": "Incoterm", "code": "INC"}
25+
{"name": "Carrier INC", "code": "CIN"}
26+
)
27+
cls.incoterm_partner = cls.env["account.incoterms"].create(
28+
{"name": "Partner INC", "code": "PIN"}
2629
)
2730
cls.intrastat_transport_mode = cls.env["intrastat.transport_mode"].create(
28-
{"name": "Incoterm", "code": "INC", "description": "DESC"}
31+
{"name": "Road", "code": "R", "description": "Road Test"}
2932
)
3033
cls.carrier = cls.env["delivery.carrier"].create(
3134
{
@@ -40,11 +43,7 @@ def setUpClass(cls):
4043
{
4144
"partner_id": cls.partner_a.id,
4245
"order_line": [
43-
Command.create(
44-
{
45-
"product_id": cls.product_1.id,
46-
}
47-
),
46+
Command.create({"product_id": cls.product_1.id}),
4847
],
4948
}
5049
)
@@ -87,3 +86,59 @@ def test_01_incoterms_intrastat_transport_propagation(self):
8786
invoice = self.order.invoice_ids[0]
8887
self.assertEqual(invoice.invoice_incoterm_id, self.incoterm)
8988
self.assertEqual(invoice.intrastat_transport_id, self.intrastat_transport_mode)
89+
90+
def test_02_priority_partner_over_carrier_and_company(self):
91+
self.partner_a.sale_incoterm_id = self.incoterm_partner
92+
order = self.env["sale.order"].create(
93+
{
94+
"partner_id": self.partner_a.id,
95+
"carrier_id": self.carrier.id,
96+
"order_line": [Command.create({"product_id": self.product_1.id})],
97+
}
98+
)
99+
order._onchange_partner_or_carrier()
100+
self.assertEqual(order.incoterm, self.incoterm_partner)
101+
order.action_confirm()
102+
self.assertEqual(order.incoterm, self.incoterm_partner)
103+
104+
def test_03_priority_carrier_when_no_partner(self):
105+
self.partner_a.sale_incoterm_id = False
106+
order = self.env["sale.order"].create(
107+
{
108+
"partner_id": self.partner_a.id,
109+
"carrier_id": self.carrier.id,
110+
"order_line": [Command.create({"product_id": self.product_1.id})],
111+
}
112+
)
113+
order._onchange_partner_or_carrier()
114+
self.assertEqual(order.incoterm, self.incoterm)
115+
order.action_confirm()
116+
self.assertEqual(order.incoterm, self.incoterm)
117+
self.assertEqual(order.intrastat_transport_id, self.intrastat_transport_mode)
118+
119+
def test_04_priority_company_when_no_partner_nor_carrier(self):
120+
self.partner_a.sale_incoterm_id = False
121+
order = self.env["sale.order"].create(
122+
{
123+
"partner_id": self.partner_a.id,
124+
"order_line": [Command.create({"product_id": self.product_1.id})],
125+
}
126+
)
127+
order._onchange_partner_or_carrier()
128+
self.assertEqual(order.incoterm, self.incoterm_company)
129+
order.action_confirm()
130+
self.assertEqual(order.incoterm, self.incoterm_company)
131+
132+
def test_05_empty_when_no_sources(self):
133+
self.partner_a.sale_incoterm_id = False
134+
self.env.company.incoterm_id = False
135+
order = self.env["sale.order"].create(
136+
{
137+
"partner_id": self.partner_a.id,
138+
"order_line": [Command.create({"product_id": self.product_1.id})],
139+
}
140+
)
141+
order._onchange_partner_or_carrier()
142+
self.assertFalse(order.incoterm)
143+
order.action_confirm()
144+
self.assertFalse(order.incoterm)

0 commit comments

Comments
 (0)