changeset 694a0303831f in modules/stock:default
details: https://hg.tryton.org/modules/stock?cmd=changeset;node=694a0303831f
description:
Enforce filling cost price of move
We set cost price only for outgoing or incoming moves.
issue9397
review321611002
diffstat:
CHANGELOG | 1 +
move.py | 23 ++++++++++++++++++++---
2 files changed, 21 insertions(+), 3 deletions(-)
diffs (62 lines):
diff -r f4bf415dd686 -r 694a0303831f CHANGELOG
--- a/CHANGELOG Wed Jun 17 14:09:55 2020 +0200
+++ b/CHANGELOG Fri Jul 03 21:22:43 2020 +0200
@@ -1,3 +1,4 @@
+* Enforce filling cost price of move
* Rename move state from cancel to cancelled
* Rename shipment states from cancel to cancelled
* Rename inventory state from cancel to cancelled
diff -r f4bf415dd686 -r 694a0303831f move.py
--- a/move.py Wed Jun 17 14:09:55 2020 +0200
+++ b/move.py Fri Jul 03 21:22:43 2020 +0200
@@ -246,8 +246,15 @@
'invisible': Eval('state') != 'done',
},
depends=['state'])
- cost_price = fields.Numeric('Cost Price', digits=price_digits,
- readonly=True)
+ cost_price = fields.Numeric(
+ "Cost Price", digits=price_digits, readonly=True,
+ states={
+ 'invisible': ~Eval('cost_price_required'),
+ 'required': (
+ (Eval('state') == 'done')
+ & Eval('cost_price_required', False)),
+ },
+ depends=['cost_price_required'])
currency = fields.Many2One('currency.currency', 'Currency',
states={
'invisible': ~Eval('unit_price_required'),
@@ -259,6 +266,9 @@
unit_price_required = fields.Function(
fields.Boolean('Unit Price Required'),
'on_change_with_unit_price_required')
+ cost_price_required = fields.Function(
+ fields.Boolean("Cost Price Required"),
+ 'on_change_with_cost_price_required')
assignation_required = fields.Function(
fields.Boolean('Assignation Required'),
'on_change_with_assignation_required')
@@ -402,6 +412,13 @@
return True
return False
+ @fields.depends('from_location', 'to_location')
+ def on_change_with_cost_price_required(self, name=None):
+ from_type = self.from_location.type if self.from_location else None
+ to_type = self.to_location.type if self.to_location else None
+ return ((from_type != 'storage' and to_type == 'storage')
+ or (from_type == 'storage' and to_type != 'storage'))
+
@fields.depends('from_location')
def on_change_with_assignation_required(self, name=None):
if self.from_location:
@@ -590,7 +607,7 @@
cost_values.append(
(move.product, cost_price,
move._cost_price_pattern))
- if move.cost_price is None:
+ if move.cost_price_required and move.cost_price is None:
if cost_price is None:
cost_price = move.product.get_multivalue(
'cost_price', **move._cost_price_pattern)