From 07464604aa61cc310d1f87e7e664a1b0be6730fa Mon Sep 17 00:00:00 2001 From: ced <> Date: Fri, 19 Oct 2007 12:15:38 +0000 Subject: [PATCH] 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 --- addons/account/product.py | 52 ++++++++++++----------- addons/stock/product.py | 79 +++++++++++++++++++++++------------ addons/stock/product_data.xml | 35 +++++++++++++++- addons/stock/stock.py | 30 +++++++++---- 4 files changed, 138 insertions(+), 58 deletions(-) diff --git a/addons/account/product.py b/addons/account/product.py index 1d42ea15cba..db89668b36f 100644 --- a/addons/account/product.py +++ b/addons/account/product.py @@ -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", diff --git a/addons/stock/product.py b/addons/stock/product.py index 8a0d997b6af..003103d3796 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -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() diff --git a/addons/stock/product_data.xml b/addons/stock/product_data.xml index f28b96d01c1..9ab36f040f3 100644 --- a/addons/stock/product_data.xml +++ b/addons/stock/product_data.xml @@ -1,6 +1,6 @@ - + property_stock_journal @@ -8,5 +8,38 @@ + + property_stock_account_output + + + + + + property_stock_account_input + + + + + + property_stock_account_output_categ + + + + + + property_stock_account_input_categ + + + + + diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 871448e5f63..4ea2262676c 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -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