From a87be1db6ab8c3d7489e4dfa6e7675e7dd7e09be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 7 Sep 2024 14:00:50 +0200 Subject: [PATCH] Do not return empty for planned deliver date of purchase line when it is in the past Closes #13298 --- modules/product_kit/purchase.py | 7 +++++++ modules/purchase/purchase.py | 16 ++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/modules/product_kit/purchase.py b/modules/product_kit/purchase.py index 877c9e84fb..384b99f8cd 100644 --- a/modules/product_kit/purchase.py +++ b/modules/product_kit/purchase.py @@ -7,6 +7,7 @@ from trytond.i18n import gettext from trytond.model import ModelSQL, ModelView, fields from trytond.modules.product import round_price from trytond.pool import Pool, PoolMeta +from trytond.transaction import Transaction from .common import ( AmendmentLineMixin, get_moves, get_shipments_returns, @@ -82,6 +83,7 @@ class LineComponent( from trytond.modules.purchase.exceptions import PartyLocationError pool = Pool() Move = pool.get('stock.move') + Date = pool.get('ir.date') if (self.quantity >= 0) != (move_type == 'in'): return @@ -100,6 +102,9 @@ class LineComponent( purchase=self.purchase.rec_name, party=self.purchase.party.rec_name)) + with Transaction().set_context(company=self.line.purchase.company.id): + today = Date.today() + move = Move() move.quantity = quantity move.unit = self.unit @@ -113,6 +118,8 @@ class LineComponent( self.line.unit_price * self.price_ratio) move.currency = self.line.purchase.currency move.planned_date = self.line.planned_delivery_date + if move.planned_date and move.planned_date < today: + move.planned_date = None move.origin = self move.origin_planned_date = move.planned_date return move diff --git a/modules/purchase/purchase.py b/modules/purchase/purchase.py index c33006f055..0e7c977066 100644 --- a/modules/purchase/purchase.py +++ b/modules/purchase/purchase.py @@ -1755,13 +1755,8 @@ class Line(sequence_ordered(), ModelSQL, ModelView): '_parent_purchase.company') def planned_delivery_date(self): pool = Pool() - Date = pool.get('ir.date') ProductSupplier = pool.get('purchase.product_supplier') - if self.purchase and self.purchase.company: - with Transaction().set_context(company=self.purchase.company.id): - today = Date.today() - else: - today = Date.today() + product_supplier = self.product_supplier if not product_supplier and self.purchase and self.purchase.company: product_supplier = ProductSupplier( @@ -1780,8 +1775,6 @@ class Line(sequence_ordered(), ModelSQL, ModelView): delivery_date = product_supplier.compute_supply_date(date=date) if delivery_date == datetime.date.max: delivery_date = None - if delivery_date and delivery_date < today: - delivery_date = None return delivery_date @classmethod @@ -1947,6 +1940,7 @@ class Line(sequence_ordered(), ModelSQL, ModelView): ''' pool = Pool() Move = pool.get('stock.move') + Date = pool.get('ir.date') if self.type != 'line': return @@ -1970,6 +1964,10 @@ class Line(sequence_ordered(), ModelSQL, ModelView): gettext('purchase.msg_purchase_supplier_location_required', purchase=self.purchase.rec_name, party=self.purchase.party.rec_name)) + + with Transaction().set_context(company=self.purchase.company.id): + today = Date.today() + move = Move() move.quantity = quantity move.unit = self.unit @@ -1982,6 +1980,8 @@ class Line(sequence_ordered(), ModelSQL, ModelView): move.unit_price = self.unit_price move.currency = self.purchase.currency move.planned_date = self.planned_delivery_date + if move.planned_date and move.planned_date < today: + move.planned_date = None move.invoice_lines = self._get_move_invoice_lines(move_type) move.origin = self move.origin_planned_date = move.planned_date