STOCK: re-implement accounting on stock moves

bzr revid: ced-abff4034a99cca7077fe6e534f2e0f7576d30b61
This commit is contained in:
ced 2007-04-25 14:08:50 +00:00
parent d3e8964986
commit 96645e1b98
5 changed files with 59 additions and 26 deletions

View File

@ -7,7 +7,7 @@
"category" : "Generic Modules/Inventory Control",
"init_xml" : [],
"demo_xml" : ["stock_demo.xml"],
"update_xml" : ["stock_workflow.xml", "stock_data.xml", "stock_incoterms.xml","stock_wizard.xml", "stock_view.xml", "stock_report.xml", "stock_sequence.xml"],
"update_xml" : ["stock_workflow.xml", "stock_data.xml", "stock_incoterms.xml","stock_wizard.xml", "stock_view.xml", "stock_report.xml", "stock_sequence.xml", "product_data.xml",],
"active": False,
"installable": True
}

View File

@ -65,4 +65,9 @@ class product_product(osv.osv):
}
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"),
}
product_category()

View File

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<terp>
<data>
<record model="ir.property" id="property_stock_journal">
<field name="name">property_stock_journal</field>
<field name="fields_id" search="[('model', '=', 'product.category'), ('name', '=', 'property_stock_journal')]"/>
<field name="value" eval="'account.journal,'+str(ref('account.stock_journal'))" model="account.journal"/>
</record>
</data>
</terp>

View File

@ -77,7 +77,7 @@ class stock_location(osv.osv):
'usage': fields.selection([('supplier','Supplier Location'),('internal','Internal Location'),('customer','Customer Location'),('inventory','Inventory'),('procurement','Procurement'),('production','Production')], 'Location type'),
'allocation_method': fields.selection([('fifo','FIFO'),('lifo','LIFO'),('nearest','Nearest')], 'Allocation Method', required=True),
'account_id': fields.many2one('account.account', string='Inventory Account', domain=[('type','=','stock_inventory')]),
'account_id': fields.many2one('account.account', string='Inventory Account', domain=[('type','!=','view')]),
'location_id': fields.many2one('stock.location', 'Parent Location', select=True),
'child_ids': fields.one2many('stock.location', 'location_id', 'Contains'),
@ -687,7 +687,6 @@ class stock_move(osv.osv):
return {'value':result}
def action_confirm(self, cr, uid, ids, context={}):
print 'Confirmed state', ids
self.write(cr, uid, ids, {'state':'confirmed'})
return True
@ -787,27 +786,41 @@ class stock_move(osv.osv):
#
# Accounting Entries
#
# acc_src = None
# acc_dest = None
# if move.location_id.account_id:
# acc_src = move.location_id.account_id.id
# if move.location_dest_id.account_id:
# acc_dest = move.location_dest_id.account_id.id
# if acc_src or acc_dest:
# test = [('product.product', move.product_id.id)]
# 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[0]
# if not acc_dest:
# acc_dest = move.product_id.product_tmpl_id.property_account_income[0]
# if acc_src != acc_dest:
# amount = move.product_qty * move.product_id.standard_price
# lines = [
# (0,0,{'name': 'Stock', 'amount': -amount, 'account_id': acc_src}),
# (0,0,{'name': 'Stock', 'amount': amount, 'account_id': acc_dest})
# ]
# self.pool.get('account.move').create(cr, uid, {'name': 'Stock', 'type':'undefined', 'line_id': lines})
acc_src = None
acc_dest = None
if move.location_id.account_id:
acc_src = move.location_id.account_id.id
if move.location_dest_id.account_id:
acc_dest = move.location_dest_id.account_id.id
if acc_src or acc_dest:
test = [('product.product', move.product_id.id)]
if move.product_id.categ_id:
test.append( ('product.category', move.product_id.categ_id.id) )
if not acc_src:
a = move.product_id.product_tmpl_id.property_account_expense
if not a:
a = move.product_id.categ_id.property_account_expense_categ
if not a:
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,))
acc_src = a[0]
if not acc_dest:
b = move.product_id.product_tmpl_id.property_account_income
if not b:
b = move.product_id.categ_id.property_account_income_categ
if not b:
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,))
acc_dest = b[0]
if not move.product_id.categ_id.property_stock_journal:
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,))
journal_id = move.product_id.categ_id.property_stock_journal[0]
if acc_src != acc_dest:
ref = move.picking_id and move.picking_id.name or False
amount = move.product_qty * move.product_id.standard_price
lines = [
(0,0,{'name': move.name, 'quantity': move.product_qty, 'debit': amount, 'account_id': acc_src, 'ref': ref}),
(0,0,{'name': move.name, 'quantity': move.product_qty, 'credit': amount, 'account_id': acc_dest, 'ref': ref})
]
self.pool.get('account.move').create(cr, uid, {'name': move.name, 'journal_id': journal_id, 'line_id': lines, 'ref': ref})
self.write(cr, uid, ids, {'state':'done'})
wf_service = netsvc.LocalService("workflow")

View File

@ -121,7 +121,10 @@ def _do_split(self, cr, uid, data, context):
move_obj.write(cr, uid, [c.id for c in complete], {'picking_id': new_picking})
for move in too_many:
move_obj.write(cr, uid, [move.id], {'product_qty' : data['form']['move%s' % move.id],'product_uos_qty':data['form']['move%s' % move.id] , 'picking_id': new_picking})
else:
for move in too_many:
move_obj.write(cr, uid, [move.id], {'product_qty' : data['form']['move%s' % move.id],'product_uos_qty':data['form']['move%s' % move.id]})
# At first we confirm the new picking (if necessary)
wf_service = netsvc.LocalService("workflow")
if new_picking: