Do not return empty for planned deliver date of purchase line when it is in the past
Closes #13298
This commit is contained in:
1 parent
48568f7856
commit
a87be1db6a
2 files changed
+15
-8
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user