Fill unit price of purchase line created automatically
Since 2f25450e11f6 the on_change_product does not always set a unit price for purchase line. But as the field is required, it must be filled for line created.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.modules.product import round_price
|
||||
@@ -59,7 +62,10 @@ class Line(order_line_mixin('purchase'), metaclass=PoolMeta):
|
||||
def get_component_order_line(self, component, **values):
|
||||
values = values.copy()
|
||||
values['purchase'] = self.purchase
|
||||
return super().get_component_order_line(component, **values)
|
||||
line = super().get_component_order_line(component, **values)
|
||||
if line.unit_price is None:
|
||||
line.unit_price = round_price(Decimal(0))
|
||||
return line
|
||||
|
||||
@classmethod
|
||||
def get_move_product_types(cls):
|
||||
|
||||
@@ -259,7 +259,7 @@ Check unit price of moves::
|
||||
>>> shipment.reload()
|
||||
>>> invoice.reload()
|
||||
>>> sorted([m.unit_price for m in shipment.incoming_moves])
|
||||
[Decimal('5.0000'), Decimal('5.0000'), Decimal('9.4545'), Decimal('14.1818')]
|
||||
[Decimal('0.0000'), Decimal('5.0000'), Decimal('9.4545'), Decimal('14.1818')]
|
||||
|
||||
Check backorder moves::
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from decimal import Decimal
|
||||
from itertools import groupby
|
||||
|
||||
from trytond.i18n import gettext
|
||||
@@ -215,6 +217,8 @@ class Production(metaclass=PoolMeta):
|
||||
factor * self.routing.supplier_quantity)
|
||||
line.purchase = purchase
|
||||
line.on_change_product()
|
||||
if line.unit_price is None:
|
||||
line.unit_price = round_price(Decimal(0))
|
||||
return line
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user