From 65cfc60c1406016a32cd90b57e7737a607df8e36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 20 Mar 2013 22:51:12 +0100 Subject: [PATCH] Remove _inherits review670002 --- move.py | 6 +++-- tests/scenario_stock_average_cost_price.rst | 25 +++++++++++------- tests/scenario_stock_shipment_out.rst | 21 ++++++++++----- tests/test_stock.py | 29 +++++++++++++++------ view/product_tree_qty.xml | 3 +-- 5 files changed, 56 insertions(+), 28 deletions(-) diff --git a/move.py b/move.py index ead5057b0e..4af38b30f3 100644 --- a/move.py +++ b/move.py @@ -1,7 +1,7 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. from decimal import Decimal -from functools import reduce +from functools import reduce, partial from trytond.model import Workflow, ModelView, ModelSQL, fields from trytond.backend import TableHandler from trytond.pyson import In, Eval, Not, Equal, If, Get, Bool @@ -385,13 +385,15 @@ class Move(Workflow, ModelSQL, ModelView): if hasattr(Product, 'cost_price'): digits = Product.cost_price.digits + write = partial(Product.write, [product]) else: digits = ProductTemplate.cost_price.digits + write = partial(ProductTemplate.write, [product.template]) new_cost_price = new_cost_price.quantize( Decimal(str(10.0 ** -digits[1]))) with Transaction().set_user(0, set_context=True): - Product.write([product], { + write({ 'cost_price': new_cost_price, }) diff --git a/tests/scenario_stock_average_cost_price.rst b/tests/scenario_stock_average_cost_price.rst index 4ec8e795f5..d638797d32 100644 --- a/tests/scenario_stock_average_cost_price.rst +++ b/tests/scenario_stock_average_cost_price.rst @@ -31,10 +31,13 @@ Create company:: >>> Currency = Model.get('currency.currency') >>> CurrencyRate = Model.get('currency.currency.rate') >>> Company = Model.get('company.company') + >>> Party = Model.get('party.party') >>> company_config = Wizard('company.company.config') >>> company_config.execute('company') >>> company = company_config.form - >>> company.name = 'Dunder Mifflin' + >>> party = Party(name='Dunder Mifflin') + >>> party.save() + >>> company.party = party >>> currencies = Currency.find([('code', '=', 'USD')]) >>> if not currencies: ... currency = Currency(name='US Dollar', symbol='$', code='USD', @@ -57,15 +60,19 @@ Reload the context:: Create product:: >>> ProductUom = Model.get('product.uom') + >>> ProductTemplate = Model.get('product.template') >>> Product = Model.get('product.product') >>> unit, = ProductUom.find([('name', '=', 'Unit')]) >>> product = Product() - >>> product.name = 'Product' - >>> product.default_uom = unit - >>> product.type = 'goods' - >>> product.list_price = Decimal('300') - >>> product.cost_price = Decimal('80') - >>> product.cost_price_method = 'average' + >>> template = ProductTemplate() + >>> template.name = 'Product' + >>> template.default_uom = unit + >>> template.type = 'goods' + >>> template.list_price = Decimal('300') + >>> template.cost_price = Decimal('80') + >>> template.cost_price_method = 'average' + >>> template.save() + >>> product.template = template >>> product.save() Get stock locations:: @@ -94,7 +101,7 @@ Make 1 unit of the product available @ 100 :: Check Cost Price is 100:: >>> product.reload() - >>> product.cost_price == Decimal('100') + >>> product.template.cost_price == Decimal('100') True Add 1 more unit @ 200:: @@ -116,5 +123,5 @@ Add 1 more unit @ 200:: Check Cost Price Average is 150:: >>> product.reload() - >>> product.cost_price == Decimal('150') + >>> product.template.cost_price == Decimal('150') True diff --git a/tests/scenario_stock_shipment_out.rst b/tests/scenario_stock_shipment_out.rst index bfceb9ae55..d2689cf220 100644 --- a/tests/scenario_stock_shipment_out.rst +++ b/tests/scenario_stock_shipment_out.rst @@ -31,10 +31,13 @@ Create company:: >>> Currency = Model.get('currency.currency') >>> CurrencyRate = Model.get('currency.currency.rate') >>> Company = Model.get('company.company') + >>> Party = Model.get('party.party') >>> company_config = Wizard('company.company.config') >>> company_config.execute('company') >>> company = company_config.form - >>> company.name = 'OPENLABS' + >>> party = Party(name='OPENLABS') + >>> party.save() + >>> company.party = party >>> currencies = Currency.find([('code', '=', 'EUR')]) >>> if not currencies: ... currency = Currency(name='Euro', symbol=u'€', code='EUR', @@ -69,15 +72,19 @@ Create category:: Create product:: >>> ProductUom = Model.get('product.uom') + >>> ProductTemplate = Model.get('product.template') >>> Product = Model.get('product.product') >>> unit, = ProductUom.find([('name', '=', 'Unit')]) >>> product = Product() - >>> product.name = 'Product' - >>> product.category = category - >>> product.default_uom = unit - >>> product.type = 'goods' - >>> product.list_price = Decimal('20') - >>> product.cost_price = Decimal('8') + >>> template = ProductTemplate() + >>> template.name = 'Product' + >>> template.category = category + >>> template.default_uom = unit + >>> template.type = 'goods' + >>> template.list_price = Decimal('20') + >>> template.cost_price = Decimal('8') + >>> template.save() + >>> product.template = template >>> product.save() Get stock locations:: diff --git a/tests/test_stock.py b/tests/test_stock.py index 7afd31ff1a..349e9e4f61 100644 --- a/tests/test_stock.py +++ b/tests/test_stock.py @@ -29,6 +29,7 @@ class StockTestCase(unittest.TestCase): def setUp(self): trytond.tests.test_tryton.install_module('stock') + self.template = POOL.get('product.template') self.product = POOL.get('product.product') self.category = POOL.get('product.category') self.uom = POOL.get('product.uom') @@ -61,7 +62,7 @@ class StockTestCase(unittest.TestCase): }]) kg, = self.uom.search([('name', '=', 'Kilogram')]) g, = self.uom.search([('name', '=', 'Gram')]) - product, = self.product.create([{ + template, = self.template.create([{ 'name': 'Test Move.internal_quantity', 'type': 'goods', 'list_price': Decimal(1), @@ -70,9 +71,12 @@ class StockTestCase(unittest.TestCase): 'cost_price_method': 'fixed', 'default_uom': kg.id, }]) + product, = self.product.create([{ + 'template': template.id, + }]) supplier, = self.location.search([('code', '=', 'SUP')]) storage, = self.location.search([('code', '=', 'STO')]) - company, = self.company.search([('name', '=', 'B2CK')]) + company, = self.company.search([('rec_name', '=', 'B2CK')]) currency = company.currency self.user.write([self.user(USER)], { 'main_company': company.id, @@ -115,7 +119,7 @@ class StockTestCase(unittest.TestCase): }]) kg, = self.uom.search([('name', '=', 'Kilogram')]) g, = self.uom.search([('name', '=', 'Gram')]) - product, = self.product.create([{ + template, = self.template.create([{ 'name': 'Test products_by_location', 'type': 'goods', 'list_price': Decimal(0), @@ -124,10 +128,13 @@ class StockTestCase(unittest.TestCase): 'cost_price_method': 'fixed', 'default_uom': kg.id, }]) + product, = self.product.create([{ + 'template': template.id, + }]) supplier, = self.location.search([('code', '=', 'SUP')]) customer, = self.location.search([('code', '=', 'CUS')]) storage, = self.location.search([('code', '=', 'STO')]) - company, = self.company.search([('name', '=', 'B2CK')]) + company, = self.company.search([('rec_name', '=', 'B2CK')]) currency = company.currency self.user.write([self.user(USER)], { 'main_company': company.id, @@ -311,14 +318,14 @@ class StockTestCase(unittest.TestCase): # Test with_childs with Transaction().start(DB_NAME, USER, context=CONTEXT) as transaction: - company, = self.company.search([('name', '=', 'B2CK')]) + company, = self.company.search([('rec_name', '=', 'B2CK')]) self.user.write([self.user(USER)], { 'main_company': company.id, 'company': company.id, }) unit, = self.uom.search([('name', '=', 'Unit')]) - product, = self.product.create([{ + template, = self.template.create([{ 'name': 'Test products_by_location', 'type': 'goods', 'list_price': Decimal(0), @@ -326,6 +333,9 @@ class StockTestCase(unittest.TestCase): 'cost_price_method': 'fixed', 'default_uom': unit.id, }]) + product, = self.product.create([{ + 'template': template.id, + }]) lost_found, = self.location.search([('type', '=', 'lost_found')]) warehouse, = self.location.search([('type', '=', 'warehouse')]) @@ -372,7 +382,7 @@ class StockTestCase(unittest.TestCase): 'name': 'Test period', }]) unit, = self.uom.search([('name', '=', 'Unit')]) - product, = self.product.create([{ + template, = self.template.create([{ 'name': 'Test period', 'type': 'goods', 'category': category.id, @@ -381,10 +391,13 @@ class StockTestCase(unittest.TestCase): 'list_price': Decimal(0), 'cost_price': Decimal(0), }]) + product, = self.product.create([{ + 'template': template.id, + }]) supplier, = self.location.search([('code', '=', 'SUP')]) customer, = self.location.search([('code', '=', 'CUS')]) storage, = self.location.search([('code', '=', 'STO')]) - company, = self.company.search([('name', '=', 'B2CK')]) + company, = self.company.search([('rec_name', '=', 'B2CK')]) currency = company.currency self.user.write([self.user(USER)], { 'main_company': company.id, diff --git a/view/product_tree_qty.xml b/view/product_tree_qty.xml index ce945fe467..ac847012af 100644 --- a/view/product_tree_qty.xml +++ b/view/product_tree_qty.xml @@ -2,12 +2,11 @@ - + -