From c037fabb4086926c413917f4e4cc8a462efaefc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 20 Dec 2017 19:30:20 +0100 Subject: [PATCH] Expose shipments_returns constructors and add missing relate from shipment to purchase issue7016 review37891003 --- purchase.py | 53 ++++++++++++++++++++++++++++++++++++++--------------- stock.xml | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 15 deletions(-) diff --git a/purchase.py b/purchase.py index 8b41516085..a9b0dae5fd 100644 --- a/purchase.py +++ b/purchase.py @@ -27,7 +27,8 @@ __all__ = ['Purchase', 'PurchaseIgnoredInvoice', 'PurchaseRecreadtedInvoice', 'PurchaseLine', 'PurchaseLineTax', 'PurchaseLineIgnoredMove', 'PurchaseLineRecreatedMove', 'PurchaseReport', 'OpenSupplier', 'HandleShipmentExceptionAsk', 'HandleShipmentException', - 'HandleInvoiceExceptionAsk', 'HandleInvoiceException'] + 'HandleInvoiceExceptionAsk', 'HandleInvoiceException', + 'get_shipments_returns', 'search_shipments_returns'] _STATES = { 'readonly': Eval('state') != 'draft', @@ -44,6 +45,36 @@ STATES = [ ] +def get_shipments_returns(model_name): + "Computes the returns or shipments" + def method(self, name): + Model = Pool().get(model_name) + shipments = set() + for line in self.lines: + for move in line.moves: + if isinstance(move.shipment, Model): + shipments.add(move.shipment.id) + return list(shipments) + return method + + +def search_shipments_returns(model_name): + "Search on shipments or returns" + def method(self, name, clause): + nested = clause[0].lstrip(name) + if nested: + return [('lines.moves.shipment' + nested,) + + tuple(clause[1:3]) + (model_name,) + tuple(clause[3:])] + else: + if isinstance(clause[2], basestring): + target = 'rec_name' + else: + target = 'id' + return [('lines.moves.shipment.' + target,) + + tuple(clause[1:3]) + (model_name,)] + return classmethod(method) + + class Purchase(Workflow, ModelSQL, ModelView, TaxableMixin): 'Purchase' __name__ = 'purchase.purchase' @@ -155,10 +186,10 @@ class Purchase(Workflow, ModelSQL, ModelView, TaxableMixin): ('exception', 'Exception'), ], 'Shipment State', readonly=True, required=True) shipments = fields.Function(fields.One2Many('stock.shipment.in', None, - 'Shipments'), 'get_shipments') + 'Shipments'), 'get_shipments', searcher='search_shipments') shipment_returns = fields.Function( fields.One2Many('stock.shipment.in.return', None, 'Shipment Returns'), - 'get_shipment_returns') + 'get_shipment_returns', searcher='search_shipment_returns') moves = fields.One2Many('stock.move', 'purchase', 'Moves', readonly=True) @classmethod @@ -540,21 +571,13 @@ class Purchase(Workflow, ModelSQL, ModelView, TaxableMixin): 'invoice_state': state, }) - def get_shipments_returns(model_name): - "Computes the returns or shipments" - def method(self, name): - Model = Pool().get(model_name) - shipments = set() - for line in self.lines: - for move in line.moves: - if isinstance(move.shipment, Model): - shipments.add(move.shipment.id) - return list(shipments) - return method - get_shipments = get_shipments_returns('stock.shipment.in') get_shipment_returns = get_shipments_returns('stock.shipment.in.return') + search_shipments = search_shipments_returns('stock.shipment.in') + search_shipment_returns = search_shipments_returns( + 'stock.shipment.in.return') + def get_shipment_state(self): ''' Return the shipment state for the purchase. diff --git a/stock.xml b/stock.xml index 488f8073b9..d57e00770a 100644 --- a/stock.xml +++ b/stock.xml @@ -33,5 +33,58 @@ this repository contains the full copyright notices and license terms. --> + + + Purchases + purchase.purchase + + + + + + + + + + + + + + form_relate + stock.shipment.in,-1 + + + + + Purchases + purchase.purchase + + + + + + + + + + + + + + form_relate + stock.shipment.in.return,-1 + + +