Skip to content

Commit 6326b76

Browse files
committed
[FIX] Fixed code for last bill date timezone issue
1 parent f2d9b34 commit 6326b76

File tree

3 files changed

+36
-29
lines changed

3 files changed

+36
-29
lines changed

purchase_backorder/models/purchase_order.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ def _compute_last_date_received(self):
4646
@api.depends("order_line.last_bill_date")
4747
def _compute_last_bill_date(self):
4848
for order in self:
49-
max_date = False
50-
for line in order.order_line:
51-
if max_date:
52-
if line.last_bill_date and max_date < line.last_bill_date:
53-
max_date = line.last_bill_date
54-
else:
55-
max_date = line.last_bill_date
56-
order.last_bill_date = max_date
49+
last_bill_date = max(
50+
(
51+
line.last_bill_date
52+
for line in order.order_line
53+
if line.last_bill_date
54+
),
55+
default=False,
56+
)
57+
order.last_bill_date = last_bill_date

purchase_backorder/models/purchase_order_line.py

+23-14
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44

55
from odoo import api, fields, models
6-
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
76

87

98
class PurchaseOrderLine(models.Model):
@@ -65,17 +64,27 @@ def _compute_last_date_received(self):
6564
@api.depends("invoice_lines.move_id.state", "invoice_lines.quantity")
6665
def _compute_last_bill_date(self):
6766
for line in self:
68-
max_date = False
69-
for inv_line in line.invoice_lines:
70-
if inv_line.move_id.state not in ["cancel"]:
71-
if inv_line.move_id.move_type == "in_invoice":
72-
if max_date and inv_line.move_id.date:
73-
if max_date < inv_line.move_id.date:
74-
max_date = inv_line.move_id.date
75-
else:
76-
max_date = inv_line.move_id.date
77-
elif inv_line.move_id.move_type == "in_refund":
78-
continue
79-
line.last_bill_date = (
80-
max_date and max_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT) or False
67+
line.last_bill_date = False
68+
invoice_lines = [
69+
inv_line
70+
for inv_line in line.invoice_lines
71+
if inv_line.move_id.state != "cancel"
72+
and inv_line.move_id.move_type == "in_invoice"
73+
]
74+
last_bill_date = max(
75+
(
76+
inv_line.move_id.date
77+
for inv_line in invoice_lines
78+
if inv_line.move_id.date
79+
),
80+
default=False,
8181
)
82+
if last_bill_date:
83+
timezone = (
84+
self._context.get("tz") or self.env.user.partner_id.tz or "UTC"
85+
)
86+
date_deadline = fields.Datetime.context_timestamp(
87+
self.with_context(tz=timezone),
88+
fields.Datetime.from_string(last_bill_date),
89+
)
90+
line.last_bill_date = date_deadline.replace(tzinfo=None)

purchase_backorder/static/description/index.html

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

99
/*
1010
:Author: David Goodger (goodger@python.org)
11-
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
11+
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z 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.
1615
1716
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1817
customize this style sheet.
@@ -275,7 +274,7 @@
275274
margin-left: 2em ;
276275
margin-right: 2em }
277276

278-
pre.code .ln { color: gray; } /* line numbers */
277+
pre.code .ln { color: grey; } /* line numbers */
279278
pre.code, code { background-color: #eeeeee }
280279
pre.code .comment, code .comment { color: #5C6576 }
281280
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -301,7 +300,7 @@
301300
span.pre {
302301
white-space: pre }
303302

304-
span.problematic, pre.problematic {
303+
span.problematic {
305304
color: red }
306305

307306
span.section-subtitle {
@@ -429,9 +428,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
429428
<div class="section" id="maintainers">
430429
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
431430
<p>This module is maintained by the OCA.</p>
432-
<a class="reference external image-reference" href="https://odoo-community.org">
433-
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
434-
</a>
431+
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
435432
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
436433
mission is to support the collaborative development of Odoo features and
437434
promote its widespread use.</p>

0 commit comments

Comments
 (0)