changeset 1abf138c5d4d in modules/production:default
details: 
https://hg.tryton.org/modules/production?cmd=changeset;node=1abf138c5d4d
description:
        Use a single assign wizard

        issue9422
        review299961011
diffstat:

 CHANGELOG      |   1 +
 __init__.py    |   2 -
 production.py  |  89 +++++++++------------------------------------------------
 production.xml |  14 ++------
 4 files changed, 19 insertions(+), 87 deletions(-)

diffs (195 lines):

diff -r 510b3d0b82d9 -r 1abf138c5d4d CHANGELOG
--- a/CHANGELOG Thu Jul 09 10:21:06 2020 +0100
+++ b/CHANGELOG Sat Jul 25 08:19:31 2020 +0200
@@ -1,3 +1,4 @@
+* Use the shipment assign wizard for production
 * Rename production state from cancel to cancelled
 
 Version 5.6.0 - 2020-05-04
diff -r 510b3d0b82d9 -r 1abf138c5d4d __init__.py
--- a/__init__.py       Thu Jul 09 10:21:06 2020 +0100
+++ b/__init__.py       Sat Jul 25 08:19:31 2020 +0200
@@ -21,7 +21,6 @@
         bom.OpenBOMTreeStart,
         bom.OpenBOMTreeTree,
         production.Production,
-        production.AssignFailed,
         product.Template,
         product.Product,
         product.ProductBom,
@@ -31,6 +30,5 @@
         ir.Cron,
         module='production', type_='model')
     Pool.register(
-        production.Assign,
         bom.OpenBOMTree,
         module='production', type_='wizard')
diff -r 510b3d0b82d9 -r 1abf138c5d4d production.py
--- a/production.py     Thu Jul 09 10:21:06 2020 +0100
+++ b/production.py     Sat Jul 25 08:19:31 2020 +0200
@@ -6,19 +6,19 @@
 from sql import Null
 
 from trytond.model import ModelView, ModelSQL, Workflow, fields, dualmethod
-from trytond.wizard import Wizard, StateTransition, StateView, Button
-from trytond.pyson import Eval, Bool, If, Id
+from trytond.pyson import Eval, Bool, If
 from trytond.pool import Pool
 from trytond.transaction import Transaction
 
 from trytond.modules.company.model import employee_field, set_employee
 from trytond.modules.product import price_digits, round_price
+from trytond.modules.stock.shipment import ShipmentAssignMixin
 
 BOM_CHANGES = ['bom', 'product', 'quantity', 'uom', 'warehouse', 'location',
     'company', 'inputs', 'outputs']
 
 
-class Production(Workflow, ModelSQL, ModelView):
+class Production(ShipmentAssignMixin, Workflow, ModelSQL, ModelView):
     "Production"
     __name__ = 'production'
 
@@ -563,12 +563,6 @@
         Move.save(moves)
 
     @classmethod
-    def view_attributes(cls):
-        return [
-            ('/tree', 'visual', If(Eval('state') == 'cancelled', 'muted', '')),
-            ]
-
-    @classmethod
     def create(cls, vlist):
         Sequence = Pool().get('ir.sequence')
         Config = Pool().get('production.configuration')
@@ -668,7 +662,9 @@
     @Workflow.transition('assigned')
     @set_employee('assigned_by')
     def assign(cls, productions):
-        pass
+        pool = Pool()
+        Move = pool.get('stock.move')
+        Move.assign([m for p in productions for m in p.assign_moves])
 
     @classmethod
     @ModelView.button
@@ -698,79 +694,22 @@
                 })
 
     @classmethod
-    @ModelView.button_action('production.wizard_assign')
+    @ModelView.button_action('production.wizard_production_assign')
     def assign_wizard(cls, productions):
         pass
 
-    @classmethod
+    @property
+    def assign_moves(self):
+        return self.inputs
+
+    @dualmethod
     @ModelView.button
     def assign_try(cls, productions):
         pool = Pool()
         Move = pool.get('stock.move')
-        if Move.assign_try([m for p in productions
-                    for m in p.inputs]):
+        if Move.assign_try(
+                [m for p in productions for m in p.assign_moves]):
             cls.assign(productions)
             return True
         else:
             return False
-
-    @classmethod
-    @ModelView.button
-    def assign_force(cls, productions):
-        pool = Pool()
-        Move = pool.get('stock.move')
-        Move.assign([m for p in productions for m in p.inputs])
-        cls.assign(productions)
-
-
-class AssignFailed(ModelView):
-    'Assign Production'
-    __name__ = 'production.assign.failed'
-
-    moves = fields.Many2Many('stock.move', None, None, 'Moves', readonly=True)
-
-    @staticmethod
-    def default_moves():
-        pool = Pool()
-        Production = pool.get('production')
-        production_id = Transaction().context.get('active_id')
-        if not production_id:
-            return []
-        production = Production(production_id)
-        return [m.id for m in production.inputs if m.state == 'draft']
-
-
-class Assign(Wizard):
-    'Assign Production'
-    __name__ = 'production.assign'
-
-    start = StateTransition()
-    failed = StateView('production.assign.failed',
-        'production.assign_failed_view_form', [
-            Button('Force Assign', 'force', 'tryton-forward',
-                states={
-                    'invisible': ~Id('stock',
-                        'group_stock_force_assignment').in_(
-                        Eval('context', {}).get('groups', [])),
-                    }),
-            Button('OK', 'end', 'tryton-ok', True),
-            ])
-    force = StateTransition()
-
-    def transition_start(self):
-        pool = Pool()
-        Production = pool.get('production')
-
-        if Production.assign_try(
-                [Production(Transaction().context['active_id'])]):
-            return 'end'
-        else:
-            return 'failed'
-
-    def transition_force(self):
-        pool = Pool()
-        Production = pool.get('production')
-
-        Production.assign_force(
-            [Production(Transaction().context['active_id'])])
-        return 'end'
diff -r 510b3d0b82d9 -r 1abf138c5d4d production.xml
--- a/production.xml    Thu Jul 09 10:21:06 2020 +0100
+++ b/production.xml    Sat Jul 25 08:19:31 2020 +0200
@@ -40,12 +40,6 @@
             <field name="group" ref="group_production_admin"/>
         </record>
 
-        <record model="ir.action.wizard" id="wizard_assign">
-            <field name="name">Assign Production</field>
-            <field name="wiz_name">production.assign</field>
-            <field name="model">production</field>
-        </record>
-
         <record model="ir.ui.view" id="production_view_list">
             <field name="model">production</field>
             <field name="type">tree</field>
@@ -299,10 +293,10 @@
                 search="[('model', '=', 'production')]"/>
         </record>
 
-        <record model="ir.ui.view" id="assign_failed_view_form">
-            <field name="model">production.assign.failed</field>
-            <field name="type">form</field>
-            <field name="name">assign_failed_form</field>
+        <record model="ir.action.wizard" id="wizard_production_assign">
+            <field name="name">Assign Production</field>
+            <field name="wiz_name">stock.shipment.assign</field>
+            <field name="model">production</field>
         </record>
 
         <record model="ir.cron" id="cron_set_cost_from_moves">

Reply via email to