From 1cf17ecf7ed5831801f94e7b369522f6170bcef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 7 Jul 2020 23:56:10 +0200 Subject: [PATCH] Add model, record and records attribute on Wizard issue9421 review309861012 --- inventory.py | 10 ++++------ product.py | 49 ++++++++++++++----------------------------------- 2 files changed, 18 insertions(+), 41 deletions(-) diff --git a/inventory.py b/inventory.py index 6dc20a93b1..bcd8c9554c 100644 --- a/inventory.py +++ b/inventory.py @@ -518,21 +518,19 @@ class Count(Wizard): def default_quantity(self, fields): pool = Pool() - Inventory = pool.get('stock.inventory') InventoryLine = pool.get('stock.inventory.line') Warning = pool.get('res.user.warning') - context = Transaction().context - inventory = Inventory(context['active_id']) values = {} - lines = InventoryLine.search(self.get_line_domain(inventory), limit=1) + lines = InventoryLine.search( + self.get_line_domain(self.record), limit=1) if not lines: warning_name = '%s.%s.count_create' % ( - inventory, self.search.search) + self.record, self.search.search) if Warning.check(warning_name): raise InventoryCountWarning(warning_name, gettext('stock.msg_inventory_count_create_line', search=self.search.search.rec_name)) - line, = InventoryLine.create([self.get_line_values(inventory)]) + line, = InventoryLine.create([self.get_line_values(self.record)]) else: line, = lines values['line'] = line.id diff --git a/product.py b/product.py index 5fbde45510..85d04c2d8d 100644 --- a/product.py +++ b/product.py @@ -600,15 +600,9 @@ class OpenProductQuantitiesByWarehouse(Wizard): open_ = StateAction('stock.act_product_quantities_warehouse_move') def do_open_(self, action): - pool = Pool() - ProductQuantitiesByWarehouse = pool.get( - 'stock.product_quantities_warehouse') - context = Transaction().context - - record = ProductQuantitiesByWarehouse(context['active_id']) - domain = [('date', '>=', record.date)] + domain = [('date', '>=', self.record.date)] action['pyson_search_value'] = PYSONEncoder().encode(domain) - action['name'] += ' (' + record.rec_name + ')' + action['name'] += ' (' + self.record.rec_name + ')' return action, {} @@ -799,14 +793,14 @@ class RecomputeCostPrice(Wizard): pool = Pool() Move = pool.get('stock.move') Product = pool.get('product.product') - Template = pool.get('product.template') - context = Transaction().context - if context['active_model'] == 'product.product': - products = Product.browse(context['active_ids']) - elif context['active_model'] == 'product.template': - templates = Template.browse(context['active_ids']) + if self.model.__name__ == 'product.product': + products = self.records + elif self.model.__name__ == 'product.template': + templates = self.records products = sum((t.products for t in templates), ()) + else: + products = [] from_ = None for sub_products in grouped_slice(products): @@ -823,18 +817,7 @@ class RecomputeCostPrice(Wizard): return {'from_': from_} def transition_recompute(self): - pool = Pool() - Product = pool.get('product.product') - Template = pool.get('product.template') - - context = Transaction().context - - if context['active_model'] == 'product.product': - products = Product.browse(context['active_ids']) - Product.recompute_cost_price(products, start=self.start.from_) - elif context['active_model'] == 'product.template': - templates = Template.browse(context['active_ids']) - Template.recompute_cost_price(templates, start=self.start.from_) + self.model.recompute_cost_price(self.records, start=self.start.from_) return 'end' @@ -858,16 +841,13 @@ class ModifyCostPrice(Wizard): def transition_modify(self): pool = Pool() Product = pool.get('product.product') - Template = pool.get('product.template') Revision = pool.get('product.cost_price.revision') Date = pool.get('ir.date') - context = Transaction().context today = Date.today() revisions = [] costs = defaultdict(list) - if context['active_model'] == 'product.product': - recompute_cost_price = Product.recompute_cost_price - products = records = Product.browse(context['active_ids']) + if self.model.__name__ == 'product.product': + products = records = list(self.records) for product in products: revision = self.get_revision(Revision) revision.product = product @@ -880,9 +860,8 @@ class ModifyCostPrice(Wizard): cost = revision.get_cost_price(product.cost_price) costs[cost].append(product) records.remove(product) - elif context['active_model'] == 'product.template': - recompute_cost_price = Template.recompute_cost_price - templates = records = Template.browse(context['active_ids']) + elif self.model.__name__ == 'product.template': + templates = records = list(self.records) for template in templates: revision = self.get_revision(Revision) revision.template = template @@ -900,7 +879,7 @@ class ModifyCostPrice(Wizard): Product.update_cost_price(costs) if records: start = min((r.date for r in revisions), default=None) - recompute_cost_price(records, start=start) + self.model.recompute_cost_price(records, start=start) return 'end' def get_revision(self, Revision):