diff --git a/__init__.py b/__init__.py index 672437e867..6372cc6771 100644 --- a/__init__.py +++ b/__init__.py @@ -1,2 +1,4 @@ -#This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. +#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 invoice import * +from product import * diff --git a/__tryton__.py b/__tryton__.py index 3ec6ab2b05..528da02b38 100644 --- a/__tryton__.py +++ b/__tryton__.py @@ -19,6 +19,7 @@ ], 'xml': [ 'invoice.xml', + 'product.xml', ], 'translation': [ 'fr_FR.csv', diff --git a/invoice.py b/invoice.py index 4471f79dea..17a69e0ea4 100644 --- a/invoice.py +++ b/invoice.py @@ -1,4 +1,5 @@ -#This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. +#This file is part of Tryton. The COPYRIGHT file at the top level of +#this repository contains the full copyright notices and license terms. "Invoice" from trytond.osv import fields, OSV @@ -1444,7 +1445,7 @@ class InvoiceLine(OSV): except: pass res['taxes'] = [] - for tax in product.supplier_taxes: + for tax in product.supplier_taxes_used: if party: if 'supplier_' + tax.group.code in party_obj._columns \ and party['supplier_' + tax.group.code]: @@ -1465,7 +1466,7 @@ class InvoiceLine(OSV): except: pass res['taxes'] = [] - for tax in product.customer_taxes: + for tax in product.customer_taxes_used: if party: if tax.group.code in party_obj._columns \ and party[tax.group.code]: @@ -1934,83 +1935,6 @@ class Party(OSV): Party() -class Category(OSV): - _name = 'product.category' - account_expense = fields.Property(type='many2one', - relation='account.account', string='Account Expense', - group_name='Accounting Properties', view_load=True, - domain="[('kind', '=', 'expense'), ('company', '=', company)]", - states={ - 'invisible': "not company", - }) - account_revenue = fields.Property(type='many2one', - relation='account.account', string='Account Revenue', - group_name='Accounting Properties', view_load=True, - domain="[('kind', '=', 'revenue'), ('company', '=', company)]", - states={ - 'invisible': "not company", - }) - -Category() - - -class Template(OSV): - _name = 'product.template' - account_expense = fields.Property(type='many2one', - string='Account Expense', group_name='Accounting Properties', - view_load=True, relation='account.account', - domain="[('kind', '=', 'expense'), ('company', '=', company)]", - states={ - 'invisible': "not company", - }, help='This account will be used instead of the one defined ' \ - 'on the category.') - account_revenue = fields.Property(type='many2one', - string='Account Revenue', group_name='Accounting Properties', - view_load=True, relation='account.account', - domain="[('kind', '=', 'revenue'), ('company', '=', company)]", - states={ - 'invisible': "not company", - }, help='This account will be used instead of the one defined ' \ - 'on the category.') - account_expense_used = fields.Function('get_account', type='many2one', - relation='account.account', string='Account Expense Used') - account_revenue_used = fields.Function('get_account', type='many2one', - relation='account.account', string='Account Revenue Used') - customer_taxes = fields.Many2Many('account.tax', - 'product_customer_taxes_rel', 'product', 'tax', - 'Customer Taxes', domain=[('parent', '=', False)]) - supplier_taxes = fields.Many2Many('account.tax', - 'product_supplier_taxes_rel', 'product', 'tax', - 'Supplier Taxes', domain=[('parent', '=', False)]) - - def __init__(self): - super(Template, self).__init__() - self._error_messages.update({ - 'missing_account': 'There is no account ' \ - 'expense/revenue define on the product ' \ - '%s (%d)', - }) - - def get_account(self, cursor, user, ids, name, arg, context=None): - account_obj = self.pool.get('account.account') - res = {} - name = name[:-5] - for product in self.browse(cursor, user, ids, context=context): - if product[name]: - res[product.id] = account_obj.name_get(cursor, user, - product[name].id, context=context)[0] - else: - if product.category[name]: - res[product.id] = account_obj.name_get(cursor, user, - product.category[name].id, context=context)[0] - else: - self.raise_user_error(cursor, 'missing_account', - (product.name, product.id), context=context) - return res - -Template() - - class FiscalYear(OSV): _name = 'account.fiscalyear' out_invoice_sequence = fields.Many2One('ir.sequence.strict', diff --git a/invoice.xml b/invoice.xml index 1f8d47f389..ba74f4664e 100644 --- a/invoice.xml +++ b/invoice.xml @@ -1,5 +1,6 @@ - + - - product.product - - - - - - - - - - - - - ]]> - - - account.fiscalyear diff --git a/product.py b/product.py new file mode 100644 index 0000000000..d9baaa2ea0 --- /dev/null +++ b/product.py @@ -0,0 +1,112 @@ +#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.osv import fields, OSV + + +class Category(OSV): + _name = 'product.category' + + account_expense = fields.Property(type='many2one', + relation='account.account', string='Account Expense', + group_name='Accounting Properties', view_load=True, + domain="[('kind', '=', 'expense'), ('company', '=', company)]", + states={ + 'invisible': "not company", + }) + account_revenue = fields.Property(type='many2one', + relation='account.account', string='Account Revenue', + group_name='Accounting Properties', view_load=True, + domain="[('kind', '=', 'revenue'), ('company', '=', company)]", + states={ + 'invisible': "not company", + }) + customer_taxes = fields.Many2Many('account.tax', + 'product_customer_taxes_rel', 'product', 'tax', + 'Customer Taxes', domain=[('parent', '=', False)]) + supplier_taxes = fields.Many2Many('account.tax', + 'product_supplier_taxes_rel', 'product', 'tax', + 'Supplier Taxes', domain=[('parent', '=', False)]) + +Category() + + +class Template(OSV): + _name = 'product.template' + + account_expense = fields.Property(type='many2one', + string='Account Expense', group_name='Accounting Properties', + view_load=True, relation='account.account', + domain="[('kind', '=', 'expense'), ('company', '=', company)]", + states={ + 'invisible': "not company", + }, help='This account will be used instead of the one defined ' \ + 'on the category.') + account_revenue = fields.Property(type='many2one', + string='Account Revenue', group_name='Accounting Properties', + view_load=True, relation='account.account', + domain="[('kind', '=', 'revenue'), ('company', '=', company)]", + states={ + 'invisible': "not company", + }, help='This account will be used instead of the one defined ' \ + 'on the category.') + account_expense_used = fields.Function('get_account', type='many2one', + relation='account.account', string='Account Expense Used') + account_revenue_used = fields.Function('get_account', type='many2one', + relation='account.account', string='Account Revenue Used') + taxes_category = fields.Boolean('Taxes Category', help='Use the taxes ' \ + 'defined on the category') + customer_taxes = fields.Many2Many('account.tax', + 'product_customer_taxes_rel', 'product', 'tax', + 'Customer Taxes', domain=[('parent', '=', False)], states={ + 'invisible': "bool(taxes_category)", + }) + supplier_taxes = fields.Many2Many('account.tax', + 'product_supplier_taxes_rel', 'product', 'tax', + 'Supplier Taxes', domain=[('parent', '=', False)], states={ + 'invisible': "bool(taxes_category)", + }) + customer_taxes_used = fields.Function('get_taxes', type='many2many', + relation='account.tax', string='Customer Taxes Used') + supplier_taxes_used = fields.Function('get_taxes', type='many2many', + relation='account.tax', string='Customer Taxes Used') + + def __init__(self): + super(Template, self).__init__() + self._error_messages.update({ + 'missing_account': 'There is no account ' \ + 'expense/revenue define on the product ' \ + '%s (%d)', + }) + + def default_taxes_category(self, cursor, user, context=None): + return False + + def get_account(self, cursor, user, ids, name, arg, context=None): + account_obj = self.pool.get('account.account') + res = {} + name = name[:-5] + for product in self.browse(cursor, user, ids, context=context): + if product[name]: + res[product.id] = account_obj.name_get(cursor, user, + product[name].id, context=context)[0] + else: + if product.category[name]: + res[product.id] = account_obj.name_get(cursor, user, + product.category[name].id, context=context)[0] + else: + self.raise_user_error(cursor, 'missing_account', + (product.name, product.id), context=context) + return res + + def get_taxes(self, cursor, user, ids, name, arg, context=None): + res = {} + name = name[:-5] + for product in self.browse(cursor, user, ids, context=context): + if product.taxes_category: + res[product.id] = [x.id for x in product.category[name]] + else: + res[product.id] = [x.id for x in product[name]] + return res + +Template() diff --git a/product.xml b/product.xml new file mode 100644 index 0000000000..1cc84b52eb --- /dev/null +++ b/product.xml @@ -0,0 +1,52 @@ + + + + + + + product.category + + + + + + + + + + + + + ]]> + + + + + product.product + + + + + + + + + ]]> + + + + +