From aec3065a67658842db8b3a41b2558f12bfa5a8df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 20 Mar 2022 01:27:59 +0100 Subject: [PATCH] Show production on stock move form issue11254 review384391002 --- CHANGELOG | 1 + message.xml | 3 +++ stock.py | 36 +++++++++++++++++++++++++++++++++++- stock.xml | 6 ++++++ view/stock_move_form.xml | 9 +++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 view/stock_move_form.xml diff --git a/CHANGELOG b/CHANGELOG index 2b35ace2c8..0f7caa211b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Show production on stock move form * Add support for Python 3.10 * Remove support for Python 3.6 diff --git a/message.xml b/message.xml index db0502676a..414a7ad9b1 100644 --- a/message.xml +++ b/message.xml @@ -9,5 +9,8 @@ this repository contains the full copyright notices and license terms. --> The product "%(product)s" on production "%(production)s" does not have any list price defined. + + Move can not be used for production input and output. + diff --git a/stock.py b/stock.py index 5ccd747c92..0055339024 100644 --- a/stock.py +++ b/stock.py @@ -1,6 +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 trytond.model import fields +from sql import Null + +from trytond.model import Check, fields from trytond.pool import Pool, PoolMeta from trytond.pyson import Eval @@ -47,11 +49,23 @@ class Move(metaclass=PoolMeta): production_input = fields.Many2One('production', 'Production Input', readonly=True, select=True, ondelete='CASCADE', domain=[('company', '=', Eval('company'))], + states={ + 'invisible': ~Eval('production_input'), + }, depends=['company']) production_output = fields.Many2One('production', 'Production Output', readonly=True, select=True, ondelete='CASCADE', domain=[('company', '=', Eval('company'))], + states={ + 'invisible': ~Eval('production_output'), + }, depends=['company']) + production = fields.Function(fields.Many2One( + 'production', "Production", + states={ + 'invisible': ~Eval('production'), + }), + 'on_change_with_production') production_cost_price_updated = fields.Boolean( "Cost Price Updated", readonly=True, states={ @@ -59,6 +73,26 @@ class Move(metaclass=PoolMeta): }, depends=['production_input', 'state']) + @classmethod + def __setup__(cls): + super().__setup__() + t = cls.__table__() + cls._sql_constraints += [ + ('production_single', Check(t, ( + (t.production_input == Null) + | (t.production_output == Null))), + 'production.msg_stock_move_production_single'), + ] + + @fields.depends( + 'production_input', '_parent_production_input.id', + 'production_output', '_parent_production_output.id') + def on_change_with_production(self, name=None): + if self.production_input: + return self.production_input.id + elif self.production_output: + return self.production_output.id + def set_effective_date(self): if not self.effective_date and self.production_input: self.effective_date = self.production_input.effective_start_date diff --git a/stock.xml b/stock.xml index 0ea1ea2932..2be12d7d06 100644 --- a/stock.xml +++ b/stock.xml @@ -25,6 +25,12 @@ this repository contains the full copyright notices and license terms. --> + + stock.move + + stock_move_form + + diff --git a/view/stock_move_form.xml b/view/stock_move_form.xml new file mode 100644 index 0000000000..6d025f8867 --- /dev/null +++ b/view/stock_move_form.xml @@ -0,0 +1,9 @@ + + + + + +