关于7.0中把原料的库存核算设为“实时(自动进行)后,原料内部调拨到生产库位投产都自动生产会计分录问题的解决
-
经过分析跟踪原代码,发现问题出在做出入库条件判断的时候没有考虑判断生产库位,没有考虑虚拟库位的特殊性:openerp默认的虚拟库位对应Company_id是null值。生成会计分录的代码就不详细解释了,记得论坛以前有人解释过。
原代码:addons/stock/stock.py
2299 if move.product_id.valuation == 'real_time': # FIXME: product valuation should perhaps be a property?
2300 if context is None:
2301 context = {}
2302 src_company_ctx = dict(context,force_company=move.location_id.company_id.id)
2303 dest_company_ctx = dict(context,force_company=move.location_dest_id.company_id.id)
2304 account_moves = []
2305 # Outgoing moves (or cross-company output part)
2306 if move.location_id.company_id <br />2307 and (move.location_id.usage == 'internal' and move.location_dest_id.usage != 'internal'<br />2308 or move.location_id.company_id != move.location_dest_id.company_id):
2309 journal_id, acc_src, acc_dest, acc_valuation = self._get_accounting_data_for_valuation(cr, uid, move, src_company_ctx)
2310 reference_amount, reference_currency_id = self._get_reference_accounting_values_for_valuation(cr, uid, move, src_company_ctx)
2311 #returning goods to supplier
2312 if move.location_dest_id.usage == 'supplier':
2313 account_moves += [(journal_id, self._create_account_move_line(cr, uid, move, acc_valuation, acc_src, reference_amount, reference_currency_id, c ontext))]
2314 else:
2315 account_moves += [(journal_id, self._create_account_move_line(cr, uid, move, acc_valuation, acc_dest, reference_amount, reference_currency_id, context))]
2316
2317 # Incoming moves (or cross-company input part)
2318 if move.location_dest_id.company_id <br />2319 and (move.location_id.usage != 'internal' and move.location_dest_id.usage == 'internal'<br />2320 or move.location_id.company_id != move.location_dest_id.company_id):
2321 journal_id, acc_src, acc_dest, acc_valuation = self._get_accounting_data_for_valuation(cr, uid, move, dest_company_ctx)
2322 reference_amount, reference_currency_id = self._get_reference_accounting_values_for_valuation(cr, uid, move, src_company_ctx)
2323 #goods return from customer
2324 if move.location_id.usage == 'customer':
2325 account_moves += [(journal_id, self._create_account_move_line(cr, uid, move, acc_dest, acc_valuation, reference_amount, reference_currency_id, context))]
代码做如下修改:
在2306行前面加入:
company_id = self.pool.get('res.users').browse(cr, uid, uid).company_id #获得用户当前公司ID
2306行改为:
if move.location_id.company_id == company_id and (move.location_id.usage == 'internal' and move.location_dest_id.usage != 'internal' and move.location_dest_id.usage != 'production' or move.location_id.company_id != move.location_dest_id.company_id and move.location_dest_id.company_id): #注意句中无换行符号
2318行改为:
if move.location_dest_id.company_id == company_id and (move.location_id.usage != 'internal' and move.location_id.usage != 'production' and move.location_dest_id.usage == 'internal' or move.location_id.company_id != move.location_dest_id.company_id and move.location_id.company_id): #注意句中无换行符号