Skip to content

Commit d67044f

Browse files
author
Tatiana Deribina
committed
[MIG] purchase_delivery_split_date: Migration to 19.0
1 parent 433d3c0 commit d67044f

File tree

8 files changed

+63
-40
lines changed

8 files changed

+63
-40
lines changed

purchase_delivery_split_date/README.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Purchase Delivery Split Date
2121
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2222
:alt: License: AGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github
24-
:target: https://github.com/OCA/purchase-workflow/tree/18.0/purchase_delivery_split_date
24+
:target: https://github.com/OCA/purchase-workflow/tree/19.0/purchase_delivery_split_date
2525
:alt: OCA/purchase-workflow
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/purchase-workflow-18-0/purchase-workflow-18-0-purchase_delivery_split_date
27+
:target: https://translation.odoo-community.org/projects/purchase-workflow-19-0/purchase-workflow-19-0-purchase_delivery_split_date
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -91,7 +91,7 @@ Bug Tracker
9191
Bugs are tracked on `GitHub Issues <https://github.com/OCA/purchase-workflow/issues>`_.
9292
In case of trouble, please check there if your issue has already been reported.
9393
If you spotted it first, help us to smash it by providing a detailed and welcomed
94-
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_delivery_split_date%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
94+
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_delivery_split_date%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
9595

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

@@ -120,6 +120,12 @@ Contributors
120120
- Denis Roussel <[email protected]>
121121
- Jacques-Etienne Baudoux (BCIM) <[email protected]>
122122

123+
Other credits
124+
-------------
125+
126+
The migration of this module from 18.0 to 19.0 was financially supported
127+
by SprintIT Ltd.
128+
123129
Maintainers
124130
-----------
125131

@@ -133,6 +139,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
133139
mission is to support the collaborative development of Odoo features and
134140
promote its widespread use.
135141

136-
This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/18.0/purchase_delivery_split_date>`_ project on GitHub.
142+
This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/19.0/purchase_delivery_split_date>`_ project on GitHub.
137143

138144
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

purchase_delivery_split_date/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
{
77
"name": "Purchase Delivery Split Date",
8-
"version": "18.0.2.0.1",
8+
"version": "19.0.1.0.0",
99
"summary": "Allows Purchase Order you confirm to generate one Incoming "
1010
"Shipment for each expected date indicated in the Purchase Order Lines",
1111
"author": (

purchase_delivery_split_date/models/purchase_order_line.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
# Copyright 2021 Jacques-Etienne Baudoux (BCIM) <[email protected]>
44
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
55

6-
from itertools import groupby
7-
86
import pytz
97

108
from odoo import fields, models
9+
from odoo.tools import groupby
1110

1211

1312
class PurchaseOrderLine(models.Model):
@@ -22,11 +21,11 @@ def _purchase_split_date_get_group_keys(self, picking):
2221
can add additional keys or replace them by others.
2322
"""
2423
tz = self.order_id.picking_type_id.warehouse_id.partner_id.tz
25-
wh_tz = pytz.timezone(tz or self.env.user.tz or "UTC")
24+
wh_tz = pytz.timezone(tz) if tz else self.env.tz
2625
date_planned_tz = self.date_planned.astimezone(pytz.utc).astimezone(wh_tz)
2726
date = date_planned_tz.date()
2827
# Split date value to obtain only the attributes year, month and day
29-
key = ({"date_planned": fields.Date.to_string(date)},)
28+
key = (("date_planned", fields.Date.to_string(date)),)
3029
return key
3130

3231
def _purchase_split_date_get_sorted_keys(self):
@@ -43,7 +42,7 @@ def _create_stock_moves(self, picking):
4342
# A picking should be provided
4443
return super()._create_stock_moves(picking)
4544
moves = self.env["stock.move"]
46-
tz = picking.picking_type_id.warehouse_id.partner_id.tz or self.env.user.tz
45+
tz = picking.picking_type_id.warehouse_id.partner_id.tz
4746
# Group the order lines by group key
4847
order_lines = sorted(
4948
self.filtered(

purchase_delivery_split_date/models/stock_move.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@
44
import pytz
55

66
from odoo import fields, models
7-
from odoo.osv import expression
7+
from odoo.fields import Domain
88
from odoo.tools import groupby
99

1010

1111
class StockMove(models.Model):
1212
_inherit = "stock.move"
1313

1414
def _purchase_split_date_get_group_keys(self):
15-
tz = self.picking_type_id.warehouse_id.partner_id.tz or self.env.user.tz
16-
wh_tz = pytz.timezone(tz or "UTC")
15+
tz = self.picking_type_id.warehouse_id.partner_id.tz
16+
wh_tz = pytz.timezone(tz) if tz else self.env.tz
1717
date_planned_tz = self.date_deadline.astimezone(pytz.utc).astimezone(wh_tz)
1818
date = date_planned_tz.date()
1919
# Split date value to obtain only the attributes year, month and day
20-
key = ({"date_planned": fields.Date.to_string(date)},)
20+
key = (("date_planned", fields.Date.to_string(date)),)
2121
return key
2222

2323
def _search_picking_for_assignation_domain(self):
2424
domain = super()._search_picking_for_assignation_domain()
2525
if self.env.context.get("purchase_delivery_split_date"):
2626
key = self._purchase_split_date_get_group_keys()
27-
tz = self.picking_type_id.warehouse_id.partner_id.tz or self.env.user.tz
28-
domain = expression.AND(
27+
tz = self.picking_type_id.warehouse_id.partner_id.tz
28+
domain = Domain.AND(
2929
[domain, self.picking_id._purchase_split_date_assign_domain(key, tz)]
3030
)
3131
return domain
@@ -70,5 +70,6 @@ def _get_new_picking_values(self):
7070
if self.env.context.get("purchase_delivery_split_date") and not vals.get(
7171
"partner_id"
7272
):
73-
vals["partner_id"] = fields.first(self.purchase_line_id.partner_id).id
73+
partners = self.purchase_line_id.partner_id
74+
vals["partner_id"] = next(iter(partners), partners).id
7475
return vals

purchase_delivery_split_date/models/stock_picking.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class StockPicking(models.Model):
1313

1414
@api.model
1515
def _purchase_split_date_assign_domain(self, key, tz):
16-
date = key[0].get("date_planned")
17-
wh_tz = pytz.timezone(tz or "UTC")
16+
date = key[0][1]
17+
wh_tz = pytz.timezone(tz) if tz else self.env.tz
1818
# The date is in local time
1919
dt_start_tz = wh_tz.localize(fields.Datetime.to_datetime(date))
2020
dt_start = dt_start_tz.astimezone(pytz.utc).replace(tzinfo=None)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The migration of this module from 18.0 to 19.0 was financially supported
2+
by SprintIT Ltd.

purchase_delivery_split_date/static/description/index.html

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ <h1>Purchase Delivery Split Date</h1>
374374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375375
!! source digest: sha256:c31a6e3528da8fa59cb4c57c78216193c920b907b5da75687b40cfff83a3cfd8
376376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/purchase-workflow/tree/18.0/purchase_delivery_split_date"><img alt="OCA/purchase-workflow" src="https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/purchase-workflow-18-0/purchase-workflow-18-0-purchase_delivery_split_date"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
377+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/purchase-workflow/tree/19.0/purchase_delivery_split_date"><img alt="OCA/purchase-workflow" src="https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/purchase-workflow-19-0/purchase-workflow-19-0-purchase_delivery_split_date"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378378
<p>When this module is installed, each Purchase Order you confirm will
379379
generate one Incoming Shipment for each schedule date indicated in the
380380
Purchase Order Lines.</p>
@@ -399,7 +399,8 @@ <h1>Purchase Delivery Split Date</h1>
399399
<li><a class="reference internal" href="#credits" id="toc-entry-7">Credits</a><ul>
400400
<li><a class="reference internal" href="#authors" id="toc-entry-8">Authors</a></li>
401401
<li><a class="reference internal" href="#contributors" id="toc-entry-9">Contributors</a></li>
402-
<li><a class="reference internal" href="#maintainers" id="toc-entry-10">Maintainers</a></li>
402+
<li><a class="reference internal" href="#other-credits" id="toc-entry-10">Other credits</a></li>
403+
<li><a class="reference internal" href="#maintainers" id="toc-entry-11">Maintainers</a></li>
403404
</ul>
404405
</li>
405406
</ul>
@@ -446,7 +447,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Bug Tracker</a></h2>
446447
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/purchase-workflow/issues">GitHub Issues</a>.
447448
In case of trouble, please check there if your issue has already been reported.
448449
If you spotted it first, help us to smash it by providing a detailed and welcomed
449-
<a class="reference external" href="https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_delivery_split_date%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
450+
<a class="reference external" href="https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_delivery_split_date%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
450451
<p>Do not contact contributors directly about support or help with technical issues.</p>
451452
</div>
452453
<div class="section" id="credits">
@@ -475,16 +476,21 @@ <h3><a class="toc-backref" href="#toc-entry-9">Contributors</a></h3>
475476
<li>Jacques-Etienne Baudoux (BCIM) &lt;<a class="reference external" href="mailto:je&#64;bcim.be">je&#64;bcim.be</a>&gt;</li>
476477
</ul>
477478
</div>
479+
<div class="section" id="other-credits">
480+
<h3><a class="toc-backref" href="#toc-entry-10">Other credits</a></h3>
481+
<p>The migration of this module from 18.0 to 19.0 was financially supported
482+
by SprintIT Ltd.</p>
483+
</div>
478484
<div class="section" id="maintainers">
479-
<h3><a class="toc-backref" href="#toc-entry-10">Maintainers</a></h3>
485+
<h3><a class="toc-backref" href="#toc-entry-11">Maintainers</a></h3>
480486
<p>This module is maintained by the OCA.</p>
481487
<a class="reference external image-reference" href="https://odoo-community.org">
482488
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
483489
</a>
484490
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
485491
mission is to support the collaborative development of Odoo features and
486492
promote its widespread use.</p>
487-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/18.0/purchase_delivery_split_date">OCA/purchase-workflow</a> project on GitHub.</p>
493+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/19.0/purchase_delivery_split_date">OCA/purchase-workflow</a> project on GitHub.</p>
488494
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
489495
</div>
490496
</div>

purchase_delivery_split_date/tests/test_purchase_delivery.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# Copyright 2014-2016 Numérigraphe SARL
22
# Copyright 2017 ForgeFlow, S.L.
33
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
4+
45
from freezegun import freeze_time
56

67
from odoo import Command
78
from odoo.fields import Datetime
89
from odoo.tests import Form
910

10-
from odoo.addons.base.tests.common import BaseCommon
11+
from odoo.addons.purchase_stock.tests.common import PurchaseTestCommon
1112

1213

13-
class TestDeliverySingle(BaseCommon):
14+
class TestDeliverySingle(PurchaseTestCommon):
1415
@classmethod
1516
def setUpClass(cls):
1617
super().setUpClass()
@@ -57,12 +58,12 @@ def setUpClass(cls):
5758

5859
cls.po = cls.env["purchase.order"].create(
5960
{
60-
"partner_id": cls.env.ref("base.res_partner_3").id,
61+
"partner_id": cls.partner_1.id,
6162
"order_line": [
6263
Command.create(
6364
{
6465
"product_id": cls.p1.id,
65-
"product_uom": cls.p1.uom_id.id,
66+
"product_uom_id": cls.p1.uom_id.id,
6667
"name": cls.p1.name,
6768
"price_unit": cls.p1.standard_price,
6869
"date_planned": cls.date_sooner,
@@ -72,7 +73,7 @@ def setUpClass(cls):
7273
Command.create(
7374
{
7475
"product_id": cls.p2.id,
75-
"product_uom": cls.p2.uom_id.id,
76+
"product_uom_id": cls.p2.uom_id.id,
7677
"name": cls.p2.name,
7778
"price_unit": cls.p2.standard_price,
7879
"date_planned": cls.date_sooner,
@@ -82,7 +83,7 @@ def setUpClass(cls):
8283
Command.create(
8384
{
8485
"product_id": cls.p1.id,
85-
"product_uom": cls.p1.uom_id.id,
86+
"product_uom_id": cls.p1.uom_id.id,
8687
"name": cls.p1.name,
8788
"price_unit": cls.p1.standard_price,
8889
"date_planned": cls.date_sooner,
@@ -120,7 +121,7 @@ def test_adding_line(self):
120121
# We first add a seller to the product
121122
self.env["product.supplierinfo"].create(
122123
{
123-
"partner_id": self.env.ref("base.res_partner_3").id,
124+
"partner_id": self.partner_1.id,
124125
"product_tmpl_id": self.p1.product_tmpl_id.id,
125126
}
126127
)
@@ -279,7 +280,7 @@ def test_purchase_line_created_after_confirm(self):
279280
Command.create(
280281
{
281282
"product_id": self.p3.id,
282-
"product_uom": self.p3.uom_id.id,
283+
"product_uom_id": self.p3.uom_id.id,
283284
"name": self.p3.name,
284285
"price_unit": self.p3.standard_price,
285286
"date_planned": new_date,
@@ -302,19 +303,27 @@ def test_purchase_line_date_change_tz_aware(self):
302303
self.po.button_confirm()
303304
line1 = self.po.order_line[0]
304305
line2 = self.po.order_line[1]
305-
self.env.user.tz = "Europe/Brussels"
306+
brussels_context = {
307+
"tz": "Europe/Brussels",
308+
}
306309
self.assertEqual(len(self.po.picking_ids), 1)
307-
line1.write({"date_planned": "2021-05-05 03:00:00"})
310+
line1.with_context(**brussels_context).write(
311+
{"date_planned": "2021-05-05 03:00:00"}
312+
)
308313
self.assertEqual(len(self.po.picking_ids), 2)
309314
# Time difference of at least +1 so should be same day (1 picking)
310-
line2.write({"date_planned": "2021-05-04 23:00:00"})
315+
line2.with_context(**brussels_context).write(
316+
{"date_planned": "2021-05-04 23:00:00"}
317+
)
311318
self.assertEqual(len(self.po.picking_ids), 1)
312319

313-
self.env.user.tz = "Etc/UTC"
320+
utc_context = {
321+
"tz": "Etc/UTC",
322+
}
314323
# No time difference so will be another day (2 pickings)
315-
line1.write({"date_planned": "2021-05-05 03:00:00"})
324+
line1.with_context(**utc_context).write({"date_planned": "2021-05-05 03:00:00"})
316325
self.assertEqual(len(self.po.picking_ids), 2)
317-
line2.write({"date_planned": "2021-05-04 23:00:00"})
326+
line2.with_context(**utc_context).write({"date_planned": "2021-05-04 23:00:00"})
318327
self.assertEqual(len(self.po.picking_ids), 2)
319328

320329
def test_create_from_form(self):
@@ -332,7 +341,7 @@ def test_po_with_services(self):
332341
{
333342
"order_id": self.po.id,
334343
"product_id": self.service_1.id,
335-
"product_uom": self.service_1.uom_id.id,
344+
"product_uom_id": self.service_1.uom_id.id,
336345
"name": self.service_1.name,
337346
"price_unit": self.service_1.standard_price,
338347
"date_planned": self.date_later,

0 commit comments

Comments
 (0)