trytond-patches/stock-Enforce-filling-cost-...

70 lines
2.9 KiB
Diff

From 443f3cb536af34952e95205bc3334b6ff77b1c39 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=80ngel=20=C3=80lvarez?= <angel@nan-tic.com>
Date: Thu, 8 Apr 2021 12:20:12 +0200
Subject: [PATCH] stock: Enforce filling cost price of move
We set cost price only for outgoing or incoming moves.
issue9397
---
move.py | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/move.py b/move.py
index 19f4401..839a393 100644
--- a/tryton/modules/stock/move.py
+++ b/tryton/modules/stock/move.py
@@ -266,8 +266,15 @@ class Move(Workflow, ModelSQL, ModelView):
'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'),
@@ -279,6 +286,9 @@ class Move(Workflow, ModelSQL, ModelView):
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')
@@ -416,6 +426,13 @@ class Move(Workflow, ModelSQL, ModelView):
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:
@@ -620,7 +637,7 @@ class Move(Workflow, ModelSQL, ModelView):
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)
--
2.25.1