Commits

Raimon Esteve (Zikzakmedia) committed a0ed927

Origin stock move when create shipment out return

Comments (0)

Files changed (2)

 
 def register():
     Pool.register(
+        Move,
         ShipmentOut,
         ShipmentOutReturn,
         module='stock_origin', type_='model')
 from trytond.transaction import Transaction
 from trytond.rpc import RPC
 
-__all__ = ['ShipmentOut', 'ShipmentOutReturn', 'CreateShipmentOutReturn']
+__all__ = ['Move', 'ShipmentOut', 'ShipmentOutReturn', 'CreateShipmentOutReturn']
 __metaclass__ = PoolMeta
 
 
+class Move:
+    __name__ = 'stock.move'
+
+    @classmethod
+    def _get_origin(cls):
+        models = super(Move, cls)._get_origin()
+        models.append('stock.shipment.out')
+        return models
+
+
 class ShipmentOut:
     __name__ = 'stock.shipment.out'
     origin = fields.Function(fields.Reference('Origin', selection='get_origin'),
 class CreateShipmentOutReturn:
     __name__ = 'stock.shipment.out.return.create'
 
+    #~ More efiency apply codereview:
+    #~ https://bugs.tryton.org/issue3561
+    #~ http://codereview.tryton.org/2391002/
+    #~ http://codereview.tryton.org/2361002/
+
     def do_start(self, action):
         pool = Pool()
         ShipmentOut = pool.get('stock.shipment.out')
         ShipmentOutReturn = pool.get('stock.shipment.out.return')
+        Move = pool.get('stock.move')
 
         action, data = super(CreateShipmentOutReturn, self).do_start(action)
         shipment_ids = Transaction().context['active_ids']
                 zip(shipment_outs, shipment_out_returns):
             shipment_out_return.origin_shipment = shipment_out
             shipment_out_return.save()
+
+            if shipment_out_return.incoming_moves:
+                Move.write(shipment_out_return.incoming_moves, {
+                    'origin': 'stock.shipment.out,%s' % shipment_out.id,
+                    })
+
         return action, data