From 7dac9d65c21f2ca5baff7df140a01faed91dfcf4 Mon Sep 17 00:00:00 2001 From: Lionel Sausin Date: Thu, 26 Nov 2015 15:31:30 +0100 Subject: [PATCH] [IMP] make the merge domain modular MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As explained by Raphaƫl Valyi in https://github.com/OCA/stock-logistics-warehouse/pull/94#discussion_r45978223 : Some may need to override this domain. Example: in Brazil we will probably separate quants of the same product depending on if it comes from national origin or if it's imported. It's the same product in the MRP for instance. But for fiscal reports we cannot mix quants and we don't want to freak with lots for product origin. In this case we would need to override this domain, but may be there are other use cases. --- stock_quant_merge/models/stock.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/stock_quant_merge/models/stock.py b/stock_quant_merge/models/stock.py index 5fed1152c..27bcaa71b 100644 --- a/stock_quant_merge/models/stock.py +++ b/stock_quant_merge/models/stock.py @@ -10,21 +10,25 @@ from openerp import models, api class StockQuant(models.Model): _inherit = 'stock.quant' + @api.multi + def _mergeable_domain(self): + """Return the quants which may be merged with the current record""" + self.ensure_one() + return [('id', '!=', self.id), + ('product_id', '=', self.product_id.id), + ('lot_id', '=', self.lot_id.id), + ('package_id', '=', self.package_id.id), + ('location_id', '=', self.location_id.id), + ('reservation_id', '=', False), + ('propagated_from_id', '=', self.propagated_from_id.id)] + @api.multi def merge_stock_quants(self): pending_quants = self.filtered(lambda x: True) for quant2merge in self: if (quant2merge in pending_quants and not quant2merge.reservation_id): - quants = self.search( - [('id', '!=', quant2merge.id), - ('product_id', '=', quant2merge.product_id.id), - ('lot_id', '=', quant2merge.lot_id.id), - ('package_id', '=', quant2merge.package_id.id), - ('location_id', '=', quant2merge.location_id.id), - ('reservation_id', '=', False), - ('propagated_from_id', '=', - quant2merge.propagated_from_id.id)]) + quants = self.search(self._mergeable_domain()) cont = 1 cost = quant2merge.cost for quant in quants: