changeset 65a463d9417e in modules/stock_split:default
details: 
https://hg.tryton.org/modules/stock_split?cmd=changeset;node=65a463d9417e
description:
        Add model, record and records attribute on Wizard

        issue9421
        review309861012
diffstat:

 stock.py |  37 ++++++++++---------------------------
 1 files changed, 10 insertions(+), 27 deletions(-)

diffs (70 lines):

diff -r e58aa7878eb2 -r 65a463d9417e stock.py
--- a/stock.py  Mon Jun 01 10:08:02 2020 +0100
+++ b/stock.py  Tue Jul 07 23:56:10 2020 +0200
@@ -108,20 +108,15 @@
     split = StateTransition()
 
     def default_start(self, fields):
-        pool = Pool()
-        Move = pool.get('stock.move')
-        default = {}
-        move = Move(Transaction().context['active_id'])
-        default['uom'] = move.uom.id
-        default['unit_digits'] = move.unit_digits
-        default['uom_category'] = move.uom.category.id
-        return default
+        return {
+            'uom': self.record.uom.id,
+            'unit_digits': self.record.unit_digits,
+            'uom_category': self.record.uom.category.id,
+            }
 
     def transition_split(self):
-        pool = Pool()
-        Move = pool.get('stock.move')
-        move = Move(Transaction().context['active_id'])
-        move.split(self.start.quantity, self.start.uom, self.start.count)
+        self.record.split(
+            self.start.quantity, self.start.uom, self.start.count)
         return 'end'
 
 
@@ -166,17 +161,6 @@
             ])
     split = StateTransition()
 
-    def get_shipment(self):
-        pool = Pool()
-        context = Transaction().context
-        if context['active_model'] in {
-                'stock.shipment.in.return',
-                'stock.shipment.out',
-                'stock.shipment.internal',
-                }:
-            Shipment = pool.get(context['active_model'])
-            return Shipment(context['active_id'])
-
     def get_moves(self, shipment):
         if shipment.__name__ == 'stock.shipment.out':
             return shipment.outgoing_moves
@@ -187,8 +171,7 @@
             return shipment.moves
 
     def default_start(self, fields):
-        shipment = self.get_shipment()
-        moves = self.get_moves(shipment)
+        moves = self.get_moves(self.record)
         move_ids = [m.id for m in moves if m.state == 'draft']
         return {
             'domain_moves': move_ids,
@@ -197,8 +180,8 @@
     def transition_split(self):
         pool = Pool()
         Move = pool.get('stock.move')
-        shipment = self.get_shipment()
-        Shipment = shipment.__class__
+        shipment = self.record
+        Shipment = self.model
         if shipment.state != 'draft':
             raise ValueError("Wrong shipment state")
         if not set(self.start.moves).issubset(self.start.domain_moves):

Reply via email to