changeset 443bfa51d3f4 in modules/production:default
details: 
https://hg.tryton.org/modules/production?cmd=changeset&node=443bfa51d3f4
description:
        Show production on stock move form

        issue11254
        review384391002
diffstat:

 CHANGELOG                |   1 +
 message.xml              |   3 +++
 stock.py                 |  36 +++++++++++++++++++++++++++++++++++-
 stock.xml                |   6 ++++++
 view/stock_move_form.xml |   9 +++++++++
 5 files changed, 54 insertions(+), 1 deletions(-)

diffs (113 lines):

diff -r f9b4c7fcdd86 -r 443bfa51d3f4 CHANGELOG
--- a/CHANGELOG Sat Mar 19 22:44:15 2022 +0100
+++ b/CHANGELOG Sun Mar 20 01:27:59 2022 +0100
@@ -1,3 +1,4 @@
+* Show production on stock move form
 * Add support for Python 3.10
 * Remove support for Python 3.6
 
diff -r f9b4c7fcdd86 -r 443bfa51d3f4 message.xml
--- a/message.xml       Sat Mar 19 22:44:15 2022 +0100
+++ b/message.xml       Sun Mar 20 01:27:59 2022 +0100
@@ -9,5 +9,8 @@
         <record model="ir.message" id="msg_missing_product_list_price">
             <field name="text">The product "%(product)s" on production 
"%(production)s" does not have any list price defined.</field>
         </record>
+        <record model="ir.message" id="msg_stock_move_production_single">
+            <field name="text">Move can not be used for production input and 
output.</field>
+        </record>
     </data>
 </tryton>
diff -r f9b4c7fcdd86 -r 443bfa51d3f4 stock.py
--- a/stock.py  Sat Mar 19 22:44:15 2022 +0100
+++ b/stock.py  Sun Mar 20 01:27:59 2022 +0100
@@ -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 @@
     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 @@
             },
         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 -r f9b4c7fcdd86 -r 443bfa51d3f4 stock.xml
--- a/stock.xml Sat Mar 19 22:44:15 2022 +0100
+++ b/stock.xml Sun Mar 20 01:27:59 2022 +0100
@@ -25,6 +25,12 @@
             <field name="action" 
ref="stock.wizard_open_product_quantities_by_warehouse"/>
         </record>
 
+        <record model="ir.ui.view" id="stock_move_view_form">
+            <field name="model">stock.move</field>
+            <field name="inherit" ref="stock.move_view_form"/>
+            <field name="name">stock_move_form</field>
+        </record>
+
     </data>
     <data noupdate="1">
 
diff -r f9b4c7fcdd86 -r 443bfa51d3f4 view/stock_move_form.xml
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/view/stock_move_form.xml  Sun Mar 20 01:27:59 2022 +0100
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<!-- This file is part of Tryton.  The COPYRIGHT file at the top level of
+this repository contains the full copyright notices and license terms. -->
+<data>
+    <xpath expr="//field[@name='shipment']" position="after">
+        <label name="production"/>
+        <field name="production" colspan="3"/>
+    </xpath>
+</data>

Reply via email to