From cb9cc9dc37af4bad89a21b468bc8de18cbe99e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 5 Jul 2017 14:51:42 +0200 Subject: [PATCH] Move cost price to product level instead of template issue6515 review41321002 --- product.py | 44 ++++---------------- product.xml | 5 --- tests/scenario_account_stock_continental.rst | 14 +++---- 3 files changed, 13 insertions(+), 50 deletions(-) diff --git a/product.py b/product.py index 585d50f601..77c6897d10 100644 --- a/product.py +++ b/product.py @@ -416,24 +416,13 @@ class UpdateCostPrice(Wizard): def default_ask_price(self, fields): pool = Pool() Product = pool.get('product.product') - Template = pool.get('product.template') context = Transaction().context default = {} - if ('product' in fields - and context['active_model'] == 'product.product'): - product = Product(context['active_id']) - template = product.template - default['product'] = product.id - elif ('template' in fields - and context['active_model'] == 'product.template'): - template = Template(context['active_id']) - product = template.products[0] - default['template'] = template.id - else: - return default - default['cost_price'] = getattr(product, 'recompute_cost_price_%s' % - product.cost_price_method)() + product = Product(context['active_id']) + default['product'] = product.id + default['cost_price'] = getattr( + product, 'recompute_cost_price_%s' % product.cost_price_method)() return default @staticmethod @@ -441,12 +430,8 @@ class UpdateCostPrice(Wizard): 'Return the product or template instance' pool = Pool() Product = pool.get('product.product') - ProductTemplate = pool.get('product.template') context = Transaction().context - if context['active_model'] == 'product.product': - return Product(context['active_id']) - else: - return ProductTemplate(context['active_id']) + return Product(context['active_id']) @classmethod def get_quantity(cls): @@ -459,10 +444,7 @@ class UpdateCostPrice(Wizard): with Transaction().set_context(locations=[l.id for l in locations], stock_date_end=stock_date_end): product = cls.get_product() - if hasattr(product.__class__, 'cost_price'): - return product.quantity - else: - return product.template.quantity + return product.quantity def transition_should_show_move(self): if self.get_quantity() != 0: @@ -540,16 +522,6 @@ class UpdateCostPrice(Wizard): def transition_update_price(self): pool = Pool() Product = pool.get('product.product') - ProductTemplate = pool.get('product.template') - - if not isinstance(Product.cost_price, TemplateFunction): - write = partial(Product.write, [self.ask_price.product]) - else: - if self.ask_price.template: - template = self.ask_price.template - else: - template = self.ask_price.product.template - write = partial(ProductTemplate.write, [template]) - - write({'cost_price': self.ask_price.cost_price}) + self.ask_price.product.set_multivalue( + 'cost_price', self.ask_price.cost_price) return 'end' diff --git a/product.xml b/product.xml index bf2d3a9c55..273ae0650c 100644 --- a/product.xml +++ b/product.xml @@ -22,11 +22,6 @@ this repository contains the full copyright notices and license terms. --> product.product,-1 - - form_action - product.template,-1 - - diff --git a/tests/scenario_account_stock_continental.rst b/tests/scenario_account_stock_continental.rst index 9e87eb8337..fa30f731d2 100644 --- a/tests/scenario_account_stock_continental.rst +++ b/tests/scenario_account_stock_continental.rst @@ -67,8 +67,6 @@ Create product:: >>> ProductUom = Model.get('product.uom') >>> unit, = ProductUom.find([('name', '=', 'Unit')]) >>> ProductTemplate = Model.get('product.template') - >>> Product = Model.get('product.product') - >>> product = Product() >>> template = ProductTemplate() >>> template.name = 'product' >>> template.default_uom = unit @@ -76,7 +74,6 @@ Create product:: >>> template.purchasable = True >>> template.salable = True >>> template.list_price = Decimal('10') - >>> template.cost_price = Decimal('5') >>> template.cost_price_method = 'fixed' >>> template.lead_time = datetime.timedelta(0) >>> template.account_expense = expense @@ -86,15 +83,14 @@ Create product:: >>> template.account_stock_customer = stock_customer >>> template.account_stock_production = stock_production >>> template.account_stock_lost_found = stock_lost_found + >>> product, = template.products + >>> product.cost_price = Decimal('5') >>> template.save() - >>> product.template = template - >>> product.save() - >>> template_average, = ProductTemplate.duplicate([template], { + >>> product, = template.products + >>> template_average, = template.duplicate({ ... 'cost_price_method': 'average', ... }) - >>> product_average, = Product.duplicate([product], { - ... 'template': template_average.id, - ... }) + >>> product_average, = template_average.products Create payment term::