Remove accounts from products

issue3805
review45111002
This commit is contained in:
Cédric Krier
2018-06-20 12:09:43 +02:00
parent 6eddfdcbd3
commit 556203c338
6 changed files with 46 additions and 124 deletions
+11 -12
View File
@@ -2,20 +2,19 @@
# this repository contains the full copyright notices and license terms.
from trytond.pool import Pool
from .product import *
from .stock import *
from .invoice import *
from .account import *
from . import product
from . import stock
from . import invoice
from . import account
def register():
Pool.register(
Category,
CategoryAccount,
Template,
TemplateAccount,
Product,
Move,
InvoiceLine,
FiscalYear,
product.Category,
product.CategoryAccount,
product.Template,
product.Product,
stock.Move,
invoice.InvoiceLine,
account.FiscalYear,
module='account_stock_anglo_saxon', type_='model')
+2 -56
View File
@@ -8,8 +8,7 @@ from trytond.pool import PoolMeta, Pool
from trytond.modules.account_product.product import (
account_used, template_property)
__all__ = ['Category', 'CategoryAccount', 'Template', 'TemplateAccount',
'Product']
__all__ = ['Category', 'CategoryAccount', 'Template', 'Product']
class Category:
@@ -76,66 +75,13 @@ class CategoryAccount:
class Template:
__metaclass__ = PoolMeta
__name__ = 'product.template'
account_cogs = fields.MultiValue(fields.Many2One('account.account',
'Account Cost of Goods Sold', domain=[
('kind', '!=', 'view'),
('company', '=', Eval('context', {}).get('company', -1)),
],
states={
'invisible': ((~Eval('context', {}).get('company'))
| Eval('account_category')
| (Eval('type') != 'goods')),
},
help='This account will be used instead of the one defined '
'on the category.',
depends=['account_category', 'type']))
@classmethod
def multivalue_model(cls, field):
pool = Pool()
if field == 'account_cogs':
return pool.get('product.template.account')
return super(Template, cls).multivalue_model(field)
@property
@account_used('account_cogs')
@account_used('account_cogs', 'account_category')
def account_cogs_used(self):
pass
class TemplateAccount:
__metaclass__ = PoolMeta
__name__ = 'product.template.account'
account_cogs = fields.Many2One(
'account.account', "Account Cost of Goods Sold",
domain=[
('kind', '!=', 'view'),
('company', '=', Eval('company', -1)),
],
depends=['company'])
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
exist = TableHandler.table_exist(cls._table)
if exist:
table = TableHandler(cls, module_name)
exist &= table.column_exist('account_cogs')
super(TemplateAccount, cls).__register__(module_name)
if not exist:
# Re-migration
cls._migrate_property([], [], [])
@classmethod
def _migrate_property(cls, field_names, value_names, fields):
field_names.append('account_cogs')
value_names.append('account_cogs')
super(TemplateAccount, cls)._migrate_property(
field_names, value_names, fields)
class Product:
__metaclass__ = PoolMeta
__name__ = 'product.product'
-6
View File
@@ -10,11 +10,5 @@ this repository contains the full copyright notices and license terms. -->
<field name="name">category_form</field>
</record>
<record model="ir.ui.view" id="template_view_form">
<field name="model">product.template</field>
<field name="inherit" ref="product.template_view_form"/>
<field name="name">template_form</field>
</record>
</data>
</tryton>
+17 -25
View File
@@ -89,9 +89,6 @@ Create chart of accounts::
>>> stock_supplier = accounts['stock_supplier']
>>> cogs = accounts['cogs']
>>> AccountJournal = Model.get('account.journal')
>>> stock_journal, = AccountJournal.find([('code', '=', 'STO')])
Create parties::
>>> Party = Model.get('party.party')
@@ -100,6 +97,21 @@ Create parties::
>>> customer = Party(name='Customer')
>>> customer.save()
Create product category::
>>> 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.account_stock = stock
>>> account_category.account_cogs = cogs
>>> account_category.account_stock_supplier = stock_supplier
>>> account_category.account_stock_customer = stock_customer
>>> account_category.account_stock_production = stock_production
>>> account_category.account_stock_lost_found = stock_lost_found
>>> account_category.save()
Create product::
>>> ProductUom = Model.get('product.uom')
@@ -114,17 +126,7 @@ Create product::
>>> template.list_price = Decimal('10')
>>> template.cost_price_method = 'fixed'
>>> template.lead_time = datetime.timedelta(0)
>>> template.account_expense = expense
>>> template.account_revenue = revenue
>>> template.account_stock = stock
>>> template.account_cogs = cogs
>>> template.account_stock_supplier = stock_supplier
>>> template.account_stock_customer = stock_customer
>>> template.account_stock_production = stock_production
>>> template.account_stock_lost_found = stock_lost_found
>>> template.account_journal_stock_supplier = stock_journal
>>> template.account_journal_stock_customer = stock_journal
>>> template.account_journal_stock_lost_found = stock_journal
>>> template.account_category = account_category
>>> product, = template.products
>>> product.cost_price = Decimal('5')
>>> template.save()
@@ -356,17 +358,7 @@ Now we will use a product with different unit of measure::
>>> template_by5.list_price = Decimal('10')
>>> template_by5.cost_price_method = 'fixed'
>>> template_by5.lead_time = datetime.timedelta(0)
>>> template_by5.account_expense = expense
>>> template_by5.account_revenue = revenue
>>> template_by5.account_stock = stock
>>> template_by5.account_cogs = cogs
>>> template_by5.account_stock_supplier = stock_supplier
>>> template_by5.account_stock_customer = stock_customer
>>> template_by5.account_stock_production = stock_production
>>> template_by5.account_stock_lost_found = stock_lost_found
>>> template_by5.account_journal_stock_supplier = stock_journal
>>> template_by5.account_journal_stock_customer = stock_journal
>>> template_by5.account_journal_stock_lost_found = stock_journal
>>> template_by5.account_category = account_category
>>> product_by5, = template_by5.products
>>> product_by5.cost_price = Decimal('5')
>>> template_by5.save()
@@ -103,9 +103,6 @@ Create chart of accounts::
>>> stock_supplier = accounts['stock_supplier']
>>> cogs = accounts['cogs']
>>> AccountJournal = Model.get('account.journal')
>>> stock_journal, = AccountJournal.find([('code', '=', 'STO')])
Create parties::
>>> Party = Model.get('party.party')
@@ -114,6 +111,21 @@ Create parties::
>>> customer = Party(name='Customer')
>>> customer.save()
Create product category::
>>> 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.account_stock = stock
>>> account_category.account_cogs = cogs
>>> account_category.account_stock_supplier = stock_supplier
>>> account_category.account_stock_customer = stock_customer
>>> account_category.account_stock_production = stock_production
>>> account_category.account_stock_lost_found = stock_lost_found
>>> account_category.save()
Create product::
>>> ProductUom = Model.get('product.uom')
@@ -129,18 +141,8 @@ Create product::
>>> template.list_price = Decimal('10')
>>> template.cost_price_method = 'fixed'
>>> template.lead_time = datetime.timedelta(0)
>>> template.account_expense = expense
>>> template.account_revenue = revenue
>>> template.account_stock = stock
>>> template.account_cogs = cogs
>>> template.account_stock_supplier = stock_supplier
>>> template.account_stock_customer = stock_customer
>>> template.account_stock_production = stock_production
>>> template.account_stock_lost_found = stock_lost_found
>>> template.account_journal_stock_supplier = stock_journal
>>> template.account_journal_stock_customer = stock_journal
>>> template.account_journal_stock_lost_found = stock_journal
>>> template.supply_on_sale = True
>>> template.account_category = account_category
>>> product, = template.products
>>> product.cost_price = Decimal('5')
>>> template.save()
-11
View File
@@ -1,11 +0,0 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath
expr="/form/notebook/page[@id='accounting']/field[@name='account_stock']"
position="after">
<label name="account_cogs"/>
<field name="account_cogs"/>
</xpath>
</data>