Move product model into product files

Add default taxes on categories
Add {customer,supplier}_taxes_used computed field
Add taxes_category boolean to specify which taxes to use
This commit is contained in:
Cédric Krier committed 2008-10-01 17:53:49 +02:00
1 parent f39ea24148
commit aa1e723fdb
6 files changed
+174 -103

No files matched your search

+3 -1
View File
@@ -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 *
+1
View File
@@ -19,6 +19,7 @@
],
'xml': [
'invoice.xml',
'product.xml',
],
'translation': [
'fr_FR.csv',
+4 -80
View File
@@ -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',
+2 -22
View File
@@ -1,5 +1,6 @@
<?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. -->
<!-- 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>
<menuitem name="Invoices" parent="account.menu_account_configuration"
@@ -674,27 +675,6 @@
</field>
</record>
<record model="ir.ui.view" id="product_view_form">
<field name="model">product.product</field>
<field name="inherit" ref="product.product_view_form"/>
<field name="arch" type="xml">
<![CDATA[
<data>
<xpath
expr="/form/notebook/page[@string=&quot;Properties&quot;]"
position="before">
<page string="Taxes" col="1">
<separator name="customer_taxes"/>
<field name="customer_taxes"/>
<separator name="supplier_taxes"/>
<field name="supplier_taxes"/>
</page>
</xpath>
</data>
]]>
</field>
</record>
<record model="ir.ui.view" id="fiscalyear_view_form">
<field name="model">account.fiscalyear</field>
<field name="inherit" ref="account.fiscalyear_view_form"/>
+112
View File
@@ -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()
+52
View File
@@ -0,0 +1,52 @@
<?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="category_view_form">
<field name="model">product.category</field>
<field name="inherit" ref="product.category_view_form"/>
<field name="arch" type="xml">
<![CDATA[
<data>
<xpath
expr="/form/notebook/page[@string=&quot;Properties&quot;]"
position="before">
<page string="Taxes" col="4">
<separator name="customer_taxes" colspan="4"/>
<field name="customer_taxes" colspan="4"/>
<separator name="supplier_taxes" colspan="4"/>
<field name="supplier_taxes" colspan="4"/>
</page>
</xpath>
</data>
]]>
</field>
</record>
<record model="ir.ui.view" id="product_view_form">
<field name="model">product.product</field>
<field name="inherit" ref="product.product_view_form"/>
<field name="arch" type="xml">
<![CDATA[
<data>
<xpath
expr="/form/notebook/page[@string=&quot;Properties&quot;]"
position="before">
<page string="Taxes" col="4">
<label name="taxes_category"/>
<field name="taxes_category"/>
<separator name="customer_taxes" colspan="4"/>
<field name="customer_taxes" colspan="4"/>
<separator name="supplier_taxes" colspan="4"/>
<field name="supplier_taxes" colspan="4"/>
</page>
</xpath>
</data>
]]>
</field>
</record>
</data>
</tryton>