Skip to content

Commit b10c5a8

Browse files
committed
Merge PR OCA#2479 into 16.0
Signed-off-by HaraldPanten
2 parents 7b541f5 + 963a54d commit b10c5a8

File tree

5 files changed

+63
-6
lines changed

5 files changed

+63
-6
lines changed

purchase_order_type/README.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ Authors
7777
Contributors
7878
~~~~~~~~~~~~
7979

80-
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
81-
* Pimolnat Suntian <pimolnats@ecosoft.co.th>
80+
- Guewen Baconnier <guewen.baconnier@camptocamp.com>
81+
- Pimolnat Suntian <pimolnats@ecosoft.co.th>
82+
- Roger Sans <roger.sans@sygel.es>
8283

8384
Maintainers
8485
~~~~~~~~~~~

purchase_order_type/models/purchase_order.py

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class PurchaseOrder(models.Model):
1717
string="Type",
1818
ondelete="restrict",
1919
domain="[('company_id', 'in', [False, company_id])]",
20+
compute="_compute_partner_order_type",
21+
store=True,
2022
)
2123

2224
@api.onchange("partner_id")
@@ -73,3 +75,13 @@ def _onchange_company(self):
7375
and self.order_type.company_id not in [self.company_id, False]
7476
):
7577
self.order_type = self._default_order_type()
78+
79+
@api.depends("partner_id")
80+
def _compute_partner_order_type(self):
81+
for record in self:
82+
if record.partner_id and not record.order_type:
83+
record.order_type = record.partner_id.purchase_type
84+
elif record.partner_id and record.order_type:
85+
record.order_type = record.order_type
86+
else:
87+
record.order_type = False
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
22
* Pimolnat Suntian <pimolnats@ecosoft.co.th>
3+
* Roger Sans <roger.sans@sygel.es>

purchase_order_type/static/description/index.html

+8-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
/*
1010
:Author: David Goodger (goodger@python.org)
11-
: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 $
1212
:Copyright: This stylesheet has been placed in the public domain.
1313
1414
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1516
1617
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1718
customize this style sheet.
@@ -274,7 +275,7 @@
274275
margin-left: 2em ;
275276
margin-right: 2em }
276277

277-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
278279
pre.code, code { background-color: #eeeeee }
279280
pre.code .comment, code .comment { color: #5C6576 }
280281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -300,7 +301,7 @@
300301
span.pre {
301302
white-space: pre }
302303

303-
span.problematic {
304+
span.problematic, pre.problematic {
304305
color: red }
305306

306307
span.section-subtitle {
@@ -428,12 +429,15 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
428429
<ul class="simple">
429430
<li>Guewen Baconnier &lt;<a class="reference external" href="mailto:guewen.baconnier&#64;camptocamp.com">guewen.baconnier&#64;camptocamp.com</a>&gt;</li>
430431
<li>Pimolnat Suntian &lt;<a class="reference external" href="mailto:pimolnats&#64;ecosoft.co.th">pimolnats&#64;ecosoft.co.th</a>&gt;</li>
432+
<li>Roger Sans &lt;<a class="reference external" href="mailto:roger.sans&#64;sygel.es">roger.sans&#64;sygel.es</a>&gt;</li>
431433
</ul>
432434
</div>
433435
<div class="section" id="maintainers">
434436
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
435437
<p>This module is maintained by the OCA.</p>
436-
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
438+
<a class="reference external image-reference" href="https://odoo-community.org">
439+
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
440+
</a>
437441
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
438442
mission is to support the collaborative development of Odoo features and
439443
promote its widespread use.</p>

purchase_order_type/tests/test_purchase_order_type.py

+39
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,42 @@ def test_purchase_order_type_company_error(self):
8888
self.assertEqual(order.company_id, self.type1.company_id)
8989
with self.assertRaises(ValidationError):
9090
order.write({"company_id": self.company2.id})
91+
92+
def test_order_type_from_partner(self):
93+
lines = []
94+
line_values = {
95+
"name": self.product1.name,
96+
"product_id": self.product1.id,
97+
"product_qty": 3,
98+
"product_uom": self.product1.uom_id.id,
99+
"price_unit": 100,
100+
}
101+
lines.append((0, 0, line_values))
102+
type_from_partner = self.po_obj.create(
103+
{
104+
"partner_id": self.partner1.id,
105+
"order_line": lines,
106+
}
107+
)
108+
109+
# Check if set order_type on sale
110+
self.assertEqual(type_from_partner.order_type, self.partner1.purchase_type)
111+
112+
partner2 = self.env.ref("base.res_partner_2")
113+
partner2.purchase_type = self.type1
114+
type_from_partner.write({"partner_id": partner2})
115+
# Check if order_type of sale has not changed
116+
self.assertNotEqual(type_from_partner.order_type, partner2.purchase_type)
117+
118+
# Check if order_type of sale has not deleted
119+
partner2.purchase_type = False
120+
type_from_partner.write({"partner_id": self.partner1})
121+
type_from_partner.write({"partner_id": partner2})
122+
self.assertEqual(type_from_partner.order_type, self.type2)
123+
124+
# Check if set order_type on sale again
125+
type_from_partner.write({"partner_id": self.partner1})
126+
type_from_partner.write({"order_type": False})
127+
type_from_partner.write({"partner_id": partner2})
128+
type_from_partner.write({"partner_id": partner2})
129+
self.assertEqual(type_from_partner.order_type, partner2.purchase_type)

0 commit comments

Comments
 (0)