From 674ded1398024148ad4311d57ebccb0fcef83b76 Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Wed, 30 May 2018 13:58:46 +0200 Subject: [PATCH] Set target field on supplier and customer moves relations This is required to make the client hide the relation field on when displaying the One2Many fields on the view. Also use filter attribute instead of Function fields issue7475 review51341002 --- stock.py | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/stock.py b/stock.py index e4911ec34a..eaea9f5f3f 100644 --- a/stock.py +++ b/stock.py @@ -148,18 +148,20 @@ class ShipmentDrop(Workflow, ModelSQL, ModelView): ], ], depends=['company'], readonly=True) - supplier_moves = fields.Function(fields.One2Many('stock.move', None, - 'Supplier Moves', - states={ - 'readonly': Eval('state').in_(['shipped', 'done', 'cancel']), - }, - depends=['state', 'supplier']), 'get_moves', 'set_moves') - customer_moves = fields.Function(fields.One2Many('stock.move', None, - 'Customer Moves', - states={ - 'readonly': Eval('state') != 'shipped', - }, - depends=['state', 'customer']), 'get_moves', 'set_moves') + supplier_moves = fields.One2Many('stock.move', 'shipment', + 'Supplier Moves', + filter=[('to_location.type', '=', 'drop')], + states={ + 'readonly': Eval('state').in_(['shipped', 'done', 'cancel']), + }, + depends=['state', 'supplier']) + customer_moves = fields.One2Many('stock.move', 'shipment', + 'Customer Moves', + filter=[('from_location.type', '=', 'drop')], + states={ + 'readonly': Eval('state') != 'shipped', + }, + depends=['state', 'customer']) code = fields.Char('Code', select=1, readonly=True) state = fields.Selection([ ('draft', 'Draft'), @@ -325,18 +327,6 @@ class ShipmentDrop(Workflow, ModelSQL, ModelView): if to_write: Move.write(*to_write) - def get_moves(self, name): - if name == 'supplier_moves': - return [m.id for m in self.moves if m.to_location.type == 'drop'] - elif name == 'customer_moves': - return [m.id for m in self.moves if m.from_location.type == 'drop'] - - @classmethod - def set_moves(cls, shipments, name, values): - if not values: - return - cls.write(shipments, {'moves': values}) - @classmethod def create(cls, vlist): pool = Pool()