Use properties for used accounts on product
A function field can not be used as when it's called with a list of records, the MissingFunction may raise an error for products that are not of asset type issue6634 review43281002
This commit is contained in:
1 parent
6e35604c1b
commit
65c5e68093
4 files changed
+133
-21
No files matched your search
+25
-20
@@ -4,7 +4,8 @@ from trytond import backend
|
||||
from trytond.model import fields
|
||||
from trytond.pyson import Eval
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.modules.account_product import MissingFunction
|
||||
from trytond.modules.account_product.product import (
|
||||
account_used, template_property)
|
||||
|
||||
__all__ = ['Category', 'CategoryAccount', 'Template', 'TemplateAccount',
|
||||
'Product']
|
||||
@@ -24,9 +25,6 @@ class Category:
|
||||
| ~Eval('accounting', False)),
|
||||
},
|
||||
depends=['account_parent', 'accounting']))
|
||||
account_depreciation_used = MissingFunction(
|
||||
fields.Many2One('account.account', 'Account Depreciation Used'),
|
||||
'missing_account', 'get_account')
|
||||
account_asset = fields.MultiValue(fields.Many2One('account.account',
|
||||
'Account Asset',
|
||||
domain=[
|
||||
@@ -39,9 +37,6 @@ class Category:
|
||||
| ~Eval('accounting', False)),
|
||||
},
|
||||
depends=['account_parent', 'accounting']))
|
||||
account_asset_used = MissingFunction(
|
||||
fields.Many2One('account.account', 'Account Asset Used'),
|
||||
'missing_account', 'get_account')
|
||||
|
||||
@classmethod
|
||||
def multivalue_model(cls, field):
|
||||
@@ -50,6 +45,16 @@ class Category:
|
||||
return pool.get('product.category.account')
|
||||
return super(Category, cls).multivalue_model(field)
|
||||
|
||||
@property
|
||||
@account_used('account_depreciation')
|
||||
def account_depreciation_used(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
@account_used('account_asset')
|
||||
def account_asset_used(self):
|
||||
pass
|
||||
|
||||
|
||||
class CategoryAccount:
|
||||
__metaclass__ = PoolMeta
|
||||
@@ -113,9 +118,6 @@ class Template:
|
||||
| Eval('accounts_category')),
|
||||
},
|
||||
depends=['active', 'depreciable', 'type', 'accounts_category']))
|
||||
account_depreciation_used = MissingFunction(
|
||||
fields.Many2One('account.account', 'Account Depreciation Used'),
|
||||
'missing_account', 'get_account')
|
||||
account_asset = fields.MultiValue(fields.Many2One('account.account',
|
||||
'Account Asset',
|
||||
domain=[
|
||||
@@ -131,9 +133,6 @@ class Template:
|
||||
| Eval('accounts_category')),
|
||||
},
|
||||
depends=['active', 'depreciable', 'type', 'accounts_category']))
|
||||
account_asset_used = MissingFunction(
|
||||
fields.Many2One('account.account', 'Account Asset Used'),
|
||||
'missing_account', 'get_account')
|
||||
depreciation_duration = fields.Integer(
|
||||
"Depreciation Duration",
|
||||
states={
|
||||
@@ -151,6 +150,16 @@ class Template:
|
||||
return pool.get('product.template.account')
|
||||
return super(Template, cls).multivalue_model(field)
|
||||
|
||||
@property
|
||||
@account_used('account_depreciation')
|
||||
def account_depreciation_used(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
@account_used('account_asset')
|
||||
def account_asset_used(self):
|
||||
pass
|
||||
|
||||
|
||||
class TemplateAccount:
|
||||
__metaclass__ = PoolMeta
|
||||
@@ -196,10 +205,6 @@ class TemplateAccount:
|
||||
class Product:
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'product.product'
|
||||
# Avoid raise of UserError from MissingFunction
|
||||
account_depreciation_used = fields.Function(
|
||||
fields.Many2One('account.account', 'Account Depreciation Used'),
|
||||
'get_template')
|
||||
account_asset_used = fields.Function(
|
||||
fields.Many2One('account.account', 'Account Asset Used'),
|
||||
'get_template')
|
||||
|
||||
account_depreciation_used = template_property('account_depreciation_used')
|
||||
account_asset_used = template_property('account_asset_used')
|
||||
@@ -53,7 +53,8 @@ for dep in info.get('depends', []):
|
||||
requires.append(get_require_version('trytond_%s' % dep))
|
||||
requires.append(get_require_version('trytond'))
|
||||
|
||||
tests_require = [get_require_version('proteus')]
|
||||
tests_require = [get_require_version('proteus'),
|
||||
get_require_version('trytond_purchase')]
|
||||
dependency_links = []
|
||||
if minor_version % 2:
|
||||
# Add development index for testing with proteus
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
=======================
|
||||
Purchase Asset Scenario
|
||||
=======================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime
|
||||
>>> from dateutil.relativedelta import relativedelta
|
||||
>>> from decimal import Decimal
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
>>> from trytond.modules.company.tests.tools import create_company, \
|
||||
... get_company
|
||||
>>> from trytond.modules.account.tests.tools import create_fiscalyear, \
|
||||
... create_chart, get_accounts
|
||||
>>> from trytond.modules.account_invoice.tests.tools import \
|
||||
... set_fiscalyear_invoice_sequences
|
||||
>>> from trytond.modules.account_asset.tests.tools \
|
||||
... import add_asset_accounts
|
||||
>>> today = datetime.date.today()
|
||||
|
||||
Install account_asset::
|
||||
|
||||
>>> config = activate_modules(['account_asset', 'purchase'])
|
||||
|
||||
Create company::
|
||||
|
||||
>>> _ = create_company()
|
||||
>>> company = get_company()
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
||||
... create_fiscalyear(company))
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Create chart of accounts::
|
||||
|
||||
>>> _ = create_chart(company)
|
||||
>>> accounts = add_asset_accounts(get_accounts(company), company)
|
||||
>>> revenue = accounts['revenue']
|
||||
>>> asset_account = accounts['asset']
|
||||
>>> expense = accounts['expense']
|
||||
>>> depreciation_account = accounts['depreciation']
|
||||
|
||||
Create products::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> asset_template = ProductTemplate()
|
||||
>>> asset_template.name = 'Asset'
|
||||
>>> asset_template.type = 'assets'
|
||||
>>> asset_template.default_uom = unit
|
||||
>>> asset_template.list_price = Decimal('1000')
|
||||
>>> asset_template.depreciable = True
|
||||
>>> asset_template.purchasable = True
|
||||
>>> asset_template.account_expense = expense
|
||||
>>> asset_template.account_revenue = revenue
|
||||
>>> asset_template.account_asset = asset_account
|
||||
>>> asset_template.account_depreciation = depreciation_account
|
||||
>>> asset_template.depreciation_duration = 24
|
||||
>>> asset_template.save()
|
||||
>>> service_product, = asset_template.products
|
||||
>>> asset_product, = asset_template.products
|
||||
>>> service_template = ProductTemplate()
|
||||
>>> service_template.name = 'Service'
|
||||
>>> service_template.type = 'service'
|
||||
>>> service_template.default_uom = unit
|
||||
>>> service_template.list_price = Decimal('10')
|
||||
>>> service_template.purchasable = True
|
||||
>>> service_template.account_expense = expense
|
||||
>>> service_template.account_revenue = revenue
|
||||
>>> service_template.save()
|
||||
>>> service_product, = service_template.products
|
||||
|
||||
Create supplier::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.save()
|
||||
|
||||
Purchase an asset mixed with services::
|
||||
|
||||
>>> Purchase = Model.get('purchase.purchase')
|
||||
>>> purchase = Purchase()
|
||||
>>> purchase.party = supplier
|
||||
>>> line = purchase.lines.new()
|
||||
>>> line.product = asset_product
|
||||
>>> line.quantity = 1
|
||||
>>> line = purchase.lines.new()
|
||||
>>> line.product = service_product
|
||||
>>> line.quantity = 1
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.click('confirm')
|
||||
>>> purchase.click('process')
|
||||
>>> invoice, = purchase.invoices
|
||||
>>> asset_line, service_line = invoice.lines
|
||||
>>> asset_line.account == asset_account
|
||||
True
|
||||
>>> service_line.account == expense
|
||||
True
|
||||
@@ -21,4 +21,8 @@ def suite():
|
||||
tearDown=doctest_teardown, encoding='utf-8',
|
||||
checker=doctest_checker,
|
||||
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
|
||||
suite.addTests(doctest.DocFileSuite('scenario_purchase_asset.rst',
|
||||
tearDown=doctest_teardown, encoding='utf-8',
|
||||
checker=doctest_checker,
|
||||
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
|
||||
return suite
|
||||
Reference in new issue
Block a user