Task-ID 818 : Account move when stock move

bzr revid: sbh@tinyerp.com-20100527071012-rha4yk3uu6yv2mfy
This commit is contained in:
sbh (Open ERP) 2010-05-27 12:40:12 +05:30
parent c149ea185c
commit 9e0d8d5eb2
8 changed files with 132 additions and 89 deletions

View File

@ -209,7 +209,15 @@ class product_category(osv.osv):
'child_id': fields.one2many('product.category', 'parent_id', string='Child Categories'),
'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of product categories."),
'type': fields.selection([('view','View'), ('normal','Normal')], 'Category Type'),
'property_stock_variation': fields.property(
'account.account',
type='many2one',
relation='account.account',
string="Stock variation Account",
method=True,
view_load=True,),
}
_defaults = {
'type' : lambda *a : 'normal',
@ -457,6 +465,9 @@ class product_product(osv.osv):
'price_extra': fields.float('Variant Price Extra', digits_compute=dp.get_precision('Sale Price')),
'price_margin': fields.float('Variant Price Margin', digits_compute=dp.get_precision('Sale Price')),
'pricelist_id': fields.dummy(string='Pricelist',relation='product.pricelist', type='many2one'),
'valuation':fields.selection([('manual_periodic','Manual Periodic Valuation'),
('real_time','Real Time valuation'),
('','')],'Valuation'),
}
def onchange_uom(self, cursor, user, ids, uom_id,uom_po_id):

View File

@ -135,6 +135,11 @@ parameter) will see those record just disappear.
<field name="name">Stock Weight</field>
<field name="digits">2</field>
</record>
<record forcecreate="True" id="property_stock_variation" model="ir.property">
<field name="name">property_stock_variation</field>
<field name="fields_id" search="[('model','=','product.category'),('name','=','property_stock_variation')]"/>
<field eval="'account.account,'+str(ref('account.a_recv'))" model="account.account" name="value"/>
<field name="company_id" ref="base.main_company"/>
</record>
</data>
</openerp>

View File

@ -147,6 +147,7 @@
<field name="price_extra" groups="base.group_extended"/>
<newline/>
<field groups="base.group_extended" name="cost_method"/>
<field name="valuation"/>
<newline/>
<field colspan="4" name="seller_ids" nolabel="1"/>
</page>
@ -215,6 +216,7 @@
<field name="name" select="1"/>
<field name="parent_id"/>
<field name="sequence" invisible="1"/>
<field name="property_stock_variation"/>
<field name="type"/>
<newline/>
</form>

View File

@ -26,6 +26,30 @@ from tools.translate import _
class product_product(osv.osv):
_inherit = "product.product"
def get_product_accounts(self, cr, uid, product_id, context={}):
""" To get the stock input account, stock output account and stock journal related to product.
@param product_id: product id
@return: dictionary which contains information regarding stock input account, stock output account and stock journal
"""
product_obj = self.pool.get('product.product').browse(cr, uid, product_id, False)
stock_input_acc = product_obj.property_stock_account_input and product_obj.property_stock_account_input.id or False
if not stock_input_acc:
stock_input_acc = product_obj.categ_id.property_stock_account_input_categ and product_obj.categ_id.property_stock_account_input_categ.id or False
stock_output_acc = product_obj.property_stock_account_output and product_obj.property_stock_account_output.id or False
if not stock_output_acc:
stock_output_acc = product_obj.categ_id.property_stock_account_output_categ and product_obj.categ_id.property_stock_account_output_categ.id or False
journal_id = product_obj.categ_id.property_stock_journal and product_obj.categ_id.property_stock_journal.id or False
res = {}
res.update({'stock_account_input': stock_input_acc})
res.update({'stock_account_output': stock_output_acc})
res.update({'stock_journal': journal_id})
return res
def do_change_standard_price(self, cr, uid, ids, datas, context={}):
"""
Changes the Standard Price of Product and creates an account move accordingly.
@ -44,10 +68,11 @@ class product_product(osv.osv):
stock_output_acc = datas.get('stock_output_account', False)
stock_input_acc = datas.get('stock_input_account', False)
journal_id = datas.get('stock_journal', False)
property_obj=self.pool.get('ir.property')
account_variation = property_obj.get(cr, uid, 'property_stock_variation', 'product.category', context=context)
move_ids = []
for rec_id in ids:
loc_ids = location_obj.search(cr, uid, [('account_id','<>',False),('usage','=','internal')])
loc_ids = location_obj.search(cr, uid,[('usage','=','internal')])
for location in location_obj.browse(cr, uid, loc_ids):
c = context.copy()
c.update({
@ -60,7 +85,7 @@ class product_product(osv.osv):
diff = product.standard_price - new_price
assert diff, _("Could not find any difference between standard price and new price!")
if qty:
location_account = location.account_id and location.account_id.id or False
location_account = account_variation and account_variation.id or False
company_id = location.company_id and location.company_id.id or False
assert location_account, _('Inventory Account is not specified for Location: %s' % (location.name))
assert company_id, _('Company is not specified in Location')

View File

@ -152,7 +152,7 @@ class stock_location(osv.osv):
'stock_real': fields.function(_product_qty_available, method=True, type='float', string='Real Stock', multi="stock"),
'stock_virtual': fields.function(_product_qty_available, method=True, type='float', string='Virtual Stock', multi="stock"),
'account_id': fields.many2one('account.account', string='Inventory Account', domain=[('type', '!=', 'view')]),
#'account_id': fields.many2one('account.account', string='Inventory Account', domain=[('type', '!=', 'view')]),
'location_id': fields.many2one('stock.location', 'Parent Location', select=True, ondelete='cascade'),
'child_ids': fields.one2many('stock.location', 'location_id', 'Contains'),
@ -916,6 +916,7 @@ class stock_picking(osv.osv):
like partner_id, address_id, delivery_date, delivery moves with product_id, product_qty, uom
"""
res = {}
move_obj = self.pool.get('stock.move')
delivery_obj = self.pool.get('stock.delivery')
product_obj = self.pool.get('product.product')
@ -1565,90 +1566,88 @@ class stock_move(osv.osv):
#
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_stock_account_input.id
if move.product_id.valuation=='real_time':
journal_id = move.product_id.categ_id.property_stock_journal and move.product_id.categ_id.property_stock_journal.id or False
if(move.location_id.usage=='internal' and move.location_dest_id.usage=='internal' and move.location_id.company_id.id!=move.location_dest_id.company_id.id) or ( move.location_id.usage=='internal' or move.location_dest_id.usage=='internal'):
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.categ_id.\
property_stock_account_input_categ.id
if not acc_src:
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 acc_dest:
acc_dest = move.product_id.product_tmpl_id.\
property_stock_account_output.id
if not acc_dest:
acc_dest = move.product_id.categ_id.\
property_stock_account_output_categ.id
acc_src = move.product_id.product_tmpl_id.\
property_stock_account_input.id
if not acc_src:
acc_src = move.product_id.categ_id.\
property_stock_account_input_categ.id
if not acc_src:
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 acc_dest:
acc_dest = move.product_id.product_tmpl_id.\
property_stock_account_output.id
if not acc_dest:
acc_dest = move.product_id.categ_id.\
property_stock_account_output_categ.id
if not acc_dest:
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 move.product_id.categ_id.property_stock_journal.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 move.product_id.categ_id.property_stock_journal.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
default_uom = move.product_id.uom_id.id
date = time.strftime('%Y-%m-%d')
q = product_uom_obj._compute_qty(cr, uid, move.product_uom.id, move.product_qty, default_uom)
if move.product_id.cost_method == 'average' and move.price_unit:
amount = q * move.price_unit
# Base computation on valuation price type
else:
company_id = move.company_id.id
context['currency_id'] = move.company_id.currency_id.id
pricetype = price_type_obj.browse(cr,uid,move.company_id.property_valuation_price_type.id)
amount_unit = move.product_id.price_get(pricetype.field, context)[move.product_id.id]
amount = amount_unit * q or 1.0
# amount = q * move.product_id.standard_price
partner_id = False
if move.picking_id:
partner_id = move.picking_id.address_id and (move.picking_id.address_id.partner_id and move.picking_id.address_id.partner_id.id or False) or False
lines = [
(0, 0, {
'name': move.name,
'quantity': move.product_qty,
'product_id': move.product_id and move.product_id.id or False,
'credit': amount,
'account_id': acc_src,
'ref': ref,
'date': date,
'partner_id': partner_id}),
(0, 0, {
'name': move.name,
'product_id': move.product_id and move.product_id.id or False,
'quantity': move.product_qty,
'debit': amount,
'account_id': acc_dest,
'ref': ref,
'date': date,
'partner_id': partner_id})
]
move_obj.create(cr, uid, {
'name': move.name,
'journal_id': journal_id,
'line_id': lines,
'ref': ref,
})
_('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
default_uom = move.product_id.uom_id.id
date = time.strftime('%Y-%m-%d')
q = product_uom_obj._compute_qty(cr, uid, move.product_uom.id, move.product_qty, default_uom)
if move.product_id.cost_method == 'average' and move.price_unit:
amount = q * move.price_unit
# Base computation on valuation price type
else:
company_id = move.company_id.id
context['currency_id'] = move.company_id.currency_id.id
pricetype = price_type_obj.browse(cr,uid,move.company_id.property_valuation_price_type.id)
amount_unit = move.product_id.price_get(pricetype.field, context)[move.product_id.id]
amount = amount_unit * q or 1.0
# amount = q * move.product_id.standard_price
partner_id = False
if move.picking_id:
partner_id = move.picking_id.address_id and (move.picking_id.address_id.partner_id and move.picking_id.address_id.partner_id.id or False) or False
lines = [
(0, 0, {
'name': move.name,
'quantity': move.product_qty,
'product_id': move.product_id and move.product_id.id or False,
'credit': amount,
'account_id': acc_src,
'ref': ref,
'date': date,
'partner_id': partner_id}),
(0, 0, {
'name': move.name,
'product_id': move.product_id and move.product_id.id or False,
'quantity': move.product_qty,
'debit': amount,
'account_id': acc_dest,
'ref': ref,
'date': date,
'partner_id': partner_id})
]
move_obj.create(cr, uid, {
'name': move.name,
'journal_id': journal_id,
'line_id': lines,
'ref': ref,
})
tracking_lot = False
if context:
tracking_lot = context.get('tracking_lot', False)
@ -2160,6 +2159,7 @@ class stock_picking_move_wizard(osv.osv_memory):
def action_move(self, cr, uid, ids, context=None):
move_obj = self.pool.get('stock.move')
picking_obj = self.pool.get('stock.picking')
account_move_obj = self.pool.get('account.move')
for act in self.read(cr, uid, ids):
move_lines = move_obj.browse(cr, uid, act['move_ids'])
for line in move_lines:

View File

@ -37,7 +37,7 @@
<record id="stock_location_14" model="stock.location">
<field name="name">Shelf 2</field>
<field name="location_id" ref="stock_location_13"/>
<field model="account.account" name="account_id" search="[('name','=','Merchandise Type B')]"/>
<!-- <field model="account.account" name="account_id" search="[('name','=','Merchandise Type B')]"/>-->
</record>
<record id="stock_location_15" model="stock.location">
<field name="name">Sub Products</field>

View File

@ -407,7 +407,7 @@
<newline/>
<field name="usage"/>
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
<field name="account_id" groups="base.group_extended"/>
<!--<field name="account_id" groups="base.group_extended"/>-->
<field name="location_id"/>
<field name="address_id" context="{'contact_display':'partner'}"/>
<field name="icon" groups="base.group_extended"/>

View File

@ -163,7 +163,7 @@ class stock_partial_picking(osv.osv_memory):
res.update({'date': time.strftime('%Y-%m-%d %H:%M:%S')})
for pick in pick_obj.browse(cr, uid, context.get('active_ids', [])):
if 'partner_id' in fields:
res.update({'partner_id': pick.address_id.partner_id.id})
res.update({'partner_id': pick.address_id.partner_id and pick.address_id.partner_id.id or False })
if 'address_id' in fields:
res.update({'address_id': pick.address_id.id})
for m in pick.move_lines: