Add default revenue/expense configuration

issue4824
review19311002
This commit is contained in:
Cédric Krier committed 2015-06-28 20:05:17 +02:00
1 parent d057a82b0c
commit 2cdca0a374
6 files changed
+97

No files matched your search

+2
View File
@@ -1,3 +1,5 @@
* Add default revenue/expense configuration
Version 3.6.0 - 2015-04-20
* Bug fixes (see mercurial logs for details)
* Add support for PyPy
+2
View File
@@ -3,6 +3,7 @@
from trytond.pool import Pool
from .product import *
from .configuration import *
def register():
@@ -13,4 +14,5 @@ def register():
Template,
TemplateCustomerTax,
TemplateSupplierTax,
Configuration,
module='account_product', type_='model')
+62
View File
@@ -0,0 +1,62 @@
# 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 trytond.pool import PoolMeta, Pool
from trytond.model import fields
from trytond.pyson import Eval
__all__ = ['Configuration']
class Configuration:
__metaclass__ = PoolMeta
__name__ = 'account.configuration'
default_product_account_expense = fields.Function(fields.Many2One(
'account.account', 'Default Account Expense',
domain=[
('kind', '=', 'expense'),
('company', '=', Eval('context', {}).get('company', -1)),
]),
'get_account', setter='set_account')
default_product_account_revenue = fields.Function(fields.Many2One(
'account.account', 'Default Account Revenue',
domain=[
('kind', '=', 'revenue'),
('company', '=', Eval('context', {}).get('company', -1)),
]),
'get_account', setter='set_account')
default_category_account_expense = fields.Function(fields.Many2One(
'account.account', 'Default Account Expense',
domain=[
('kind', '=', 'expense'),
('company', '=', Eval('context', {}).get('company', -1)),
]),
'get_account', setter='set_account')
default_category_account_revenue = fields.Function(fields.Many2One(
'account.account', 'Default Account Revenue',
domain=[
('kind', '=', 'revenue'),
('company', '=', Eval('context', {}).get('company', -1)),
]),
'get_account', setter='set_account')
@classmethod
def _get_account_field(cls, name):
pool = Pool()
ModelField = pool.get('ir.model.field')
if name in ['default_product_account_expense',
'default_product_account_revenue']:
field, = ModelField.search([
('model.model', '=', 'product.template'),
('name', '=', name[len('default_product_'):]),
], limit=1)
return field
elif name in ['default_category_account_expense',
'default_category_account_revenue']:
field, = ModelField.search([
('model.model', '=', 'product.category'),
('name', '=', name[len('default_category_'):]),
], limit=1)
return field
return super(Configuration, cls)._get_account_field(name)
+12
View File
@@ -0,0 +1,12 @@
<?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. -->
<tryton>
<data>
<record model="ir.ui.view" id="configuration_view_form">
<field name="model">account.configuration</field>
<field name="inherit" ref="account.configuration_view_form"/>
<field name="name">configuration_form</field>
</record>
</data>
</tryton>
+1
View File
@@ -7,3 +7,4 @@ depends:
product
xml:
product.xml
configuration.xml
+18
View File
@@ -0,0 +1,18 @@
<?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/field[@name='default_account_payable']"
position="after">
<separator id="product" string="Product" colspan="4"/>
<label name="default_product_account_expense"/>
<field name="default_product_account_expense"/>
<label name="default_product_account_revenue"/>
<field name="default_product_account_revenue"/>
<separator id="category" string="Category" colspan="4"/>
<label name="default_category_account_expense"/>
<field name="default_category_account_expense"/>
<label name="default_category_account_revenue"/>
<field name="default_category_account_revenue"/>
</xpath>
</data>