Add stock account properties on product

We can not use the same properties than the accounting for the accounting on stock move.

bzr revid: ced-9b95b7da8b3423cad4e6177516e0f7c4d9063844
This commit is contained in:
ced 2007-10-19 12:15:38 +00:00
parent a609fb30c6
commit 07464604aa
4 changed files with 138 additions and 58 deletions

View File

@ -36,23 +36,23 @@ class product_category(osv.osv):
_inherit = "product.category"
_columns = {
'property_account_income_categ': fields.property(
'account.account',
type='many2one',
relation='account.account',
string="Income Account",
method=True,
view_load=True,
group_name="Accounting Properties",
help="This account will be used, instead of the default one, to value incoming stock for the current product category"),
'account.account',
type='many2one',
relation='account.account',
string="Income Account",
method=True,
view_load=True,
group_name="Accounting Properties",
help="This account will be used, instead of the default one, to value incoming stock for the current product category"),
'property_account_expense_categ': fields.property(
'account.account',
type='many2one',
relation='account.account',
string="Expense Account",
method=True,
view_load=True,
group_name="Accounting Properties",
help="This account will be used, instead of the default one, to value outgoing stock for the current product category"),
'account.account',
type='many2one',
relation='account.account',
string="Expense Account",
method=True,
view_load=True,
group_name="Accounting Properties",
help="This account will be used, instead of the default one, to value outgoing stock for the current product category"),
}
product_category()
@ -62,22 +62,26 @@ product_category()
class product_template(osv.osv):
_inherit = "product.template"
_columns = {
'taxes_id': fields.many2many('account.tax', 'product_taxes_rel', 'prod_id', 'tax_id', 'Customer Taxes', domain=[('parent_id','=',False)]),
'supplier_taxes_id': fields.many2many('account.tax', 'product_supplier_taxes_rel', 'prod_id', 'tax_id', 'Supplier Taxes', domain=[('parent_id', '=', False)]),
'taxes_id': fields.many2many('account.tax', 'product_taxes_rel',
'prod_id', 'tax_id', 'Customer Taxes',
domain=[('parent_id','=',False)]),
'supplier_taxes_id': fields.many2many('account.tax',
'product_supplier_taxes_rel', 'prod_id', 'tax_id',
'Supplier Taxes', domain=[('parent_id', '=', False)]),
'property_account_income': fields.property(
'account.account',
type='many2one',
relation='account.account',
string="Income Account",
type='many2one',
relation='account.account',
string="Income Account",
method=True,
view_load=True,
group_name="Accounting Properties",
help="This account will be used, instead of the default one, to value incoming stock for the current product"),
'property_account_expense': fields.property(
'account.account',
type='many2one',
relation='account.account',
string="Expense Account",
type='many2one',
relation='account.account',
string="Expense Account",
method=True,
view_load=True,
group_name="Accounting Properties",

View File

@ -29,45 +29,72 @@
##############################################################################
from osv import fields, osv
import ir
class product_product(osv.osv):
_name = 'product.template'
_inherit = 'product.template'
_columns = {
'property_stock_procurement': fields.property(
'stock.location',
type='many2one',
relation='stock.location',
string="Procurement Location",
method=True,
view_load=True,
group_name="Inventory Properties",
help="For the current product (template), this stock location will be used, instead of the default one, as the source location for stock moves generated by procurements"),
'stock.location',
type='many2one',
relation='stock.location',
string="Procurement Location",
method=True,
view_load=True,
group_name="Inventory Properties",
help="For the current product (template), this stock location will be used, instead of the default one, as the source location for stock moves generated by procurements"),
'property_stock_production': fields.property(
'stock.location',
type='many2one',
relation='stock.location',
string="Production Location",
method=True,
view_load=True,
group_name="Inventory Properties",
help="For the current product (template), this stock location will be used, instead of the default one, as the source location for stock moves generated by production orders"),
'stock.location',
type='many2one',
relation='stock.location',
string="Production Location",
method=True,
view_load=True,
group_name="Inventory Properties",
help="For the current product (template), this stock location will be used, instead of the default one, as the source location for stock moves generated by production orders"),
'property_stock_inventory': fields.property(
'stock.location',
type='many2one',
relation='stock.location',
string="Inventory Location",
method=True,
view_load=True,
group_name="Inventory Properties",
help="For the current product (template), this stock location will be used, instead of the default one, as the source location for stock moves generated when you do an inventory"),
'stock.location',
type='many2one',
relation='stock.location',
string="Inventory Location",
method=True,
view_load=True,
group_name="Inventory Properties",
help="For the current product (template), this stock location will be used, instead of the default one, as the source location for stock moves generated when you do an inventory"),
'property_stock_account_input': fields.property('account.account',
type='many2one', relation='account.account',
string='Stock Input Account', method=True, view_load=True,
group_name='Stock Accounting Properties',
help='This account will be used, instead of the default one, to value input stock'),
'property_stock_account_output': fields.property('account.account',
type='many2one', relation='account.account',
string='Stock Output Account', method=True, view_load=True,
group_name='Stock Accounting Properties',
help='This account will be used, instead of the default one, to value output stock'),
}
product_product()
class product_category(osv.osv):
_inherit = 'product.category'
_columns = {
'property_stock_journal': fields.property('account.journal', relation='account.journal', type='many2one', string='Stock journal', method=True, view_load=True, group_name="Accounting Properties", help="This journal will be used for the accounting move generated by stock move"),
'property_stock_journal': fields.property('account.journal',
relation='account.journal', type='many2one',
string='Stock journal', method=True, view_load=True,
group_name="Accounting Properties",
help="This journal will be used for the accounting move generated by stock move"),
'property_stock_account_input_categ': fields.property('account.account',
type='many2one', relation='account.account',
string='Stock Input Account', method=True, view_load=True,
group_name='Stock Accounting Properties',
help='This account will be used to value the input stock'),
'property_stock_account_output_categ': fields.property('account.account',
type='many2one', relation='account.account',
string='Stock Output Account', method=True, view_load=True,
group_name='Stock Accounting Properties',
help='This account will be used to value the output stock'),
}
product_category()

View File

@ -1,6 +1,6 @@
<?xml version="1.0"?>
<terp>
<data>
<data noupdate="1">
<record model="ir.property" id="property_stock_journal">
<field name="name">property_stock_journal</field>
@ -8,5 +8,38 @@
<field name="value" eval="'account.journal,'+str(ref('account.stock_journal'))" model="account.journal"/>
</record>
<record model="ir.property" id="property_stock_account_output_prd"
forcecreate="True">
<field name="name">property_stock_account_output</field>
<field name="fields_id"
search="[('model','=','product.template'),('name','=','property_stock_account_output')]"/>
<field name="value" eval="False"/>
<field name="company_id" ref="base.main_company"/>
</record>
<record model="ir.property" id="property_stock_account_input_prd"
forcecreate="True">
<field name="name">property_stock_account_input</field>
<field name="fields_id"
search="[('model','=','product.template'),('name','=','property_stock_account_input')]"/>
<field name="value" eval="False"/>
<field name="company_id" ref="base.main_company"/>
</record>
<record model="ir.property" id="property_stock_account_output_categ"
forcecreate="True">
<field name="name">property_stock_account_output_categ</field>
<field name="fields_id"
search="[('model','=','product.category'),('name','=','property_stock_account_output_categ')]"/>
<field name="value" eval="False"/>
<field name="company_id" ref="base.main_company"/>
</record>
<record model="ir.property" id="property_stock_account_input_categ"
forcecreate="True">
<field name="name">property_stock_account_input_categ</field>
<field name="fields_id"
search="[('model','=','product.category'),('name','=','property_stock_account_input_categ')]"/>
<field name="value" eval="False"/>
<field name="company_id" ref="base.main_company"/>
</record>
</data>
</terp>

View File

@ -846,19 +846,35 @@ class stock_move(osv.osv):
if move.product_id.categ_id:
test.append( ('product.category', move.product_id.categ_id.id) )
if not acc_src:
acc_src = move.product_id.product_tmpl_id.property_account_expense.id
acc_src = move.product_id.product_tmpl_id.\
property_stock_account_output.id
if not acc_src:
acc_src = move.product_id.categ_id.property_account_expense_categ.id
acc_src = move.product_id.categ_id.\
property_stock_account_output_categ.id
if not acc_src:
raise osv.except_osv('Error !', 'There is no expense account defined for this product: "%s" (id:%d)' % (move.product_id.name, move.product_id.id,))
raise osv.except_osv('Error!',
'There is no stock output account defined ' \
'for this product: "%s" (id: %d)' % \
(move.product_id.name,
move.product_id.id,))
if not acc_dest:
acc_dest = move.product_id.product_tmpl_id.property_account_income.id
acc_dest = move.product_id.product_tmpl_id.\
property_stock_account_input.id
if not acc_dest:
acc_dest = move.product_id.categ_id.property_account_income_categ.id
acc_dest = move.product_id.categ_id.\
property_stock_account_input_categ.id
if not acc_dest:
raise osv.except_osv('Error !', 'There is no income account defined for this product: "%s" (id:%d)' % (move.product_id.name, move.product_id.id,))
raise osv.except_osv('Error!',
'There is no stock input account defined ' \
'for this product: "%s" (id: %d)' % \
(move.product_id.name,
move.product_id.id,))
if not move.product_id.categ_id.property_stock_journal.id:
raise osv.except_osv('Error !', 'There is no journal define on the product category: "%s" (id:%d)' % (move.product_id.categ_id.name, move.product_id.categ_id.id,))
raise osv.except_osv('Error!',
'There is no journal defined '\
'on the product category: "%s" (id: %d)' % \
(move.product_id.categ_id.name,
move.product_id.categ_id.id,))
journal_id = move.product_id.categ_id.property_stock_journal.id
if acc_src != acc_dest:
ref = move.picking_id and move.picking_id.name or False