From db33534e22c9df585407d623dac28a5d8c40a2b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 20 Jun 2018 12:09:51 +0200 Subject: [PATCH] Remove accounts from products issue3805 review45111002 --- product.py | 14 -------------- sale.py | 7 ++----- tests/scenario_sale.rst | 20 +++++++++++++++----- tests/scenario_sale_modify_header.rst | 12 ++++++++++-- tests/scenario_sale_reporting.rst | 27 +++++++++++++++++++-------- 5 files changed, 46 insertions(+), 34 deletions(-) diff --git a/product.py b/product.py index 6fd33eaa78..450afcc148 100644 --- a/product.py +++ b/product.py @@ -33,20 +33,6 @@ class Template: }, depends=['active', 'salable']) - @classmethod - def __setup__(cls): - super(Template, cls).__setup__() - required = ~Eval('account_category', False) & Eval('salable', False) - if not cls.account_revenue.states.get('required'): - cls.account_revenue.states['required'] = required - else: - cls.account_revenue.states['required'] = ( - cls.account_revenue.states['required'] | required) - if 'account_category' not in cls.account_revenue.depends: - cls.account_revenue.depends.append('account_category') - if 'salable' not in cls.account_revenue.depends: - cls.account_revenue.depends.append('salable') - @classmethod def __register__(cls, module_name): TableHandler = backend.get('TableHandler') diff --git a/sale.py b/sale.py index 9373b5602a..a9cde72e34 100644 --- a/sale.py +++ b/sale.py @@ -1409,11 +1409,8 @@ class SaleLine(sequence_ordered(), ModelSQL, ModelView): 'product': self.product.rec_name, }) else: - for name in ['default_product_account_revenue', - 'default_category_account_revenue']: - invoice_line.account = account_config.get_multivalue(name) - if invoice_line.account: - break + invoice_line.account = account_config.get_multivalue( + 'default_category_account_revenue') if not invoice_line.account: self.raise_user_error('missing_default_account_revenue', { 'sale': self.sale.rec_name, diff --git a/tests/scenario_sale.rst b/tests/scenario_sale.rst index 42499c0293..57a29d208e 100644 --- a/tests/scenario_sale.rst +++ b/tests/scenario_sale.rst @@ -60,6 +60,19 @@ Create parties:: >>> customer = Party(name='Customer') >>> customer.save() +Create account categories:: + + >>> ProductCategory = Model.get('product.category') + >>> account_category = ProductCategory(name="Account Category") + >>> account_category.accounting = True + >>> account_category.account_expense = expense + >>> account_category.account_revenue = revenue + >>> account_category.save() + + >>> account_category_tax, = account_category.duplicate() + >>> account_category_tax.customer_taxes.append(tax) + >>> account_category_tax.save() + Create product:: >>> ProductUom = Model.get('product.uom') @@ -73,9 +86,7 @@ Create product:: >>> template.purchasable = True >>> template.salable = True >>> template.list_price = Decimal('10') - >>> template.account_expense = expense - >>> template.account_revenue = revenue - >>> template.customer_taxes.append(tax) + >>> template.account_category = account_category_tax >>> template.save() >>> product, = template.products @@ -85,8 +96,7 @@ Create product:: >>> template.type = 'service' >>> template.salable = True >>> template.list_price = Decimal('30') - >>> template.account_expense = expense - >>> template.account_revenue = revenue + >>> template.account_category = account_category >>> template.save() >>> service, = template.products diff --git a/tests/scenario_sale_modify_header.rst b/tests/scenario_sale_modify_header.rst index 8ebf80b192..d4137baef6 100644 --- a/tests/scenario_sale_modify_header.rst +++ b/tests/scenario_sale_modify_header.rst @@ -38,6 +38,15 @@ Create tax and tax rule:: >>> no_tax.origin_tax = tax >>> foreign.save() +Create account categories:: + + >>> ProductCategory = Model.get('product.category') + >>> account_category = ProductCategory(name="Account Category") + >>> account_category.accounting = True + >>> account_category.account_revenue = revenue + >>> account_category.customer_taxes.append(tax) + >>> account_category.save() + Create product:: >>> ProductUom = Model.get('product.uom') @@ -50,8 +59,7 @@ Create product:: >>> template.type = 'goods' >>> template.salable = True >>> template.list_price = Decimal('10') - >>> template.account_revenue = revenue - >>> template.customer_taxes.append(tax) + >>> template.account_category = account_category >>> template.save() >>> product, = template.products diff --git a/tests/scenario_sale_reporting.rst b/tests/scenario_sale_reporting.rst index 30577bb23d..f8b51cd146 100644 --- a/tests/scenario_sale_reporting.rst +++ b/tests/scenario_sale_reporting.rst @@ -65,12 +65,19 @@ Create parties:: >>> address.subdivision = new_york >>> customer2.save() +Create account categories:: + + >>> Category = Model.get('product.category') + >>> account_category = Category(name="Account Category") + >>> account_category.accounting = True + >>> account_category.account_revenue = revenue + >>> account_category.save() + Create products:: >>> ProductUom = Model.get('product.uom') >>> unit, = ProductUom.find([('name', '=', 'Unit')]) >>> ProductTemplate = Model.get('product.template') - >>> Category = Model.get('product.category') >>> template1 = ProductTemplate() >>> template1.name = "Product1" @@ -78,7 +85,7 @@ Create products:: >>> template1.type = 'service' >>> template1.salable = True >>> template1.list_price = Decimal('10') - >>> template1.account_revenue = revenue + >>> template1.account_category = account_category >>> template1.save() >>> product1, = template1.products @@ -186,15 +193,16 @@ Check sale reporting per categories:: ... time_series = CategoryTimeseries.find([]) ... tree = CategoryTree.find([]) >>> len(reports) - 3 + 4 >>> with config.set_context(context=context): ... sorted((r.category.id, r.number, r.revenue) for r in reports) == \ ... sorted([(category_child1.id, 2, Decimal('30')), ... (category_root2.id, 2, Decimal('30')), - ... (category_child2.id, 1, Decimal('10'))]) + ... (category_child2.id, 1, Decimal('10')), + ... (account_category.id, 2, Decimal('40'))]) True >>> len(time_series) - 5 + 7 >>> with config.set_context(context=context): ... sorted((r.category.id, str(r.date), r.number, r.revenue) ... for r in time_series) == sorted( @@ -202,16 +210,19 @@ Check sale reporting per categories:: ... (category_root2.id, str(sale1.sale_date.replace(day=1)), 1, Decimal('20')), ... (category_child2.id, str(sale1.sale_date.replace(day=1)), 1, Decimal('10')), ... (category_child1.id, str(sale2.sale_date.replace(day=1)), 1, Decimal('10')), - ... (category_root2.id, str(sale2.sale_date.replace(day=1)), 1, Decimal('10'))]) + ... (category_root2.id, str(sale2.sale_date.replace(day=1)), 1, Decimal('10')), + ... (account_category.id, str(sale1.sale_date.replace(day=1)), 1, Decimal('30')), + ... (account_category.id, str(sale2.sale_date.replace(day=1)), 1, Decimal('10'))]) True >>> len(tree) - 4 + 5 >>> with config.set_context(context=context): ... sorted((r.name, r.revenue) for r in tree) == sorted([ ... (u'Root1', Decimal('40')), ... (u'Child1', Decimal('30')), ... (u'Child2', Decimal('10')), - ... (u'Root2', Decimal('30'))]) + ... (u'Root2', Decimal('30')), + ... (u'Account Category', Decimal('40'))]) True Check sale reporting per regions::