[IMP] purchase, stock_account: No stock valuation for consumable products (which mean also no difference in anglo saxon mode for them)

This commit is contained in:
qdp-odoo
2015-10-21 16:46:21 +02:00
parent 8a9ce7505e
commit 1be45e56cc
2 changed files with 55 additions and 55 deletions
+48 -49
View File
@@ -87,55 +87,54 @@ class AccountInvoice(models.Model):
"""
inv = i_line.invoice_id
company_currency = inv.company_id.currency_id
if i_line.product_id and i_line.product_id.valuation == 'real_time':
if i_line.product_id.type in ('product', 'consu'):
# get the fiscal position
fpos = i_line.invoice_id.fiscal_position_id
# get the price difference account at the product
acc = i_line.product_id.property_account_creditor_price_difference
if not acc:
# if not found on the product get the price difference account at the category
acc = i_line.product_id.categ_id.property_account_creditor_price_difference_categ
acc = fpos.map_account(acc).id
# reference_account_id is the stock input account
reference_account_id = i_line.product_id.product_tmpl_id.get_product_accounts(fiscal_pos=fpos)['stock_input'].id
diff_res = []
account_prec = inv.company_id.currency_id.decimal_places
# calculate and write down the possible price difference between invoice price and product price
for line in res:
if line.get('invl_id', 0) == i_line.id and reference_account_id == line['account_id']:
uom = i_line.product_id.uom_id
valuation_price_unit = uom._compute_price(i_line.product_id.standard_price, i_line.uom_id.id)
if i_line.product_id.cost_method != 'standard' and i_line.purchase_line_id:
#for average/fifo/lifo costing method, fetch real cost price from incomming moves
stock_move_obj = self.env['stock.move']
valuation_stock_move = stock_move_obj.search([('purchase_line_id', '=', i_line.purchase_line_id.id)], limit=1)
if valuation_stock_move:
valuation_price_unit = valuation_stock_move[0].price_unit
if inv.currency_id.id != company_currency.id:
valuation_price_unit = company_currency.compute(inv.currency_id, valuation_price_unit, context={'date': inv.date_invoice})
if valuation_price_unit != i_line.price_unit and line['price_unit'] == i_line.price_unit and acc:
# price with discount and without tax included
price_unit = i_line.price_unit * (1 - (i_line.discount or 0.0) / 100.0)
if line['tax_ids']:
#line['tax_ids'] is like [(4, tax_id, None), (4, tax_id2, None)...]
taxes = self.env['account.tax'].browse([x[1] for x in line['tax_ids']])
price_unit = taxes.compute_all(price_unit, currency=inv.currency_id, quantity=line['quantity'])['total_excluded']
price_line = round(valuation_price_unit * line['quantity'], account_prec)
price_diff = round(price_unit - price_line, account_prec)
line.update({'price': price_line})
diff_res.append({
'type': 'src',
'name': i_line.name[:64],
'price_unit': round(price_diff / line['quantity'], account_prec),
'quantity': line['quantity'],
'price': price_diff,
'account_id': acc,
'product_id': line['product_id'],
'uom_id': line['uom_id'],
'account_analytic_id': line['account_analytic_id'],
})
return diff_res
if i_line.product_id and i_line.product_id.valuation == 'real_time' and i_line.product_id.type == 'product':
# get the fiscal position
fpos = i_line.invoice_id.fiscal_position_id
# get the price difference account at the product
acc = i_line.product_id.property_account_creditor_price_difference
if not acc:
# if not found on the product get the price difference account at the category
acc = i_line.product_id.categ_id.property_account_creditor_price_difference_categ
acc = fpos.map_account(acc).id
# reference_account_id is the stock input account
reference_account_id = i_line.product_id.product_tmpl_id.get_product_accounts(fiscal_pos=fpos)['stock_input'].id
diff_res = []
account_prec = inv.company_id.currency_id.decimal_places
# calculate and write down the possible price difference between invoice price and product price
for line in res:
if line.get('invl_id', 0) == i_line.id and reference_account_id == line['account_id']:
uom = i_line.product_id.uom_id
valuation_price_unit = uom._compute_price(i_line.product_id.standard_price, i_line.uom_id.id)
if i_line.product_id.cost_method != 'standard' and i_line.purchase_line_id:
#for average/fifo/lifo costing method, fetch real cost price from incomming moves
stock_move_obj = self.env['stock.move']
valuation_stock_move = stock_move_obj.search([('purchase_line_id', '=', i_line.purchase_line_id.id)], limit=1)
if valuation_stock_move:
valuation_price_unit = valuation_stock_move[0].price_unit
if inv.currency_id.id != company_currency.id:
valuation_price_unit = company_currency.compute(inv.currency_id, valuation_price_unit, context={'date': inv.date_invoice})
if valuation_price_unit != i_line.price_unit and line['price_unit'] == i_line.price_unit and acc:
# price with discount and without tax included
price_unit = i_line.price_unit * (1 - (i_line.discount or 0.0) / 100.0)
if line['tax_ids']:
#line['tax_ids'] is like [(4, tax_id, None), (4, tax_id2, None)...]
taxes = self.env['account.tax'].browse([x[1] for x in line['tax_ids']])
price_unit = taxes.compute_all(price_unit, currency=inv.currency_id, quantity=line['quantity'])['total_excluded']
price_line = round(valuation_price_unit * line['quantity'], account_prec)
price_diff = round(price_unit - price_line, account_prec)
line.update({'price': price_line})
diff_res.append({
'type': 'src',
'name': i_line.name[:64],
'price_unit': round(price_diff / line['quantity'], account_prec),
'quantity': line['quantity'],
'price': price_diff,
'account_id': acc,
'product_id': line['product_id'],
'uom_id': line['uom_id'],
'account_analytic_id': line['account_analytic_id'],
})
return diff_res
return []
+7 -6
View File
@@ -40,7 +40,7 @@ class account_invoice_line(osv.osv):
return round(price, inv.currency_id.decimal_places)
def get_invoice_line_account(self, type, product, fpos, company):
if company.anglo_saxon_accounting and type in ('in_invoice', 'in_refund') and product and product.type in ('consu', 'product'):
if company.anglo_saxon_accounting and type in ('in_invoice', 'in_refund') and product and product.type == 'product':
accounts = product.product_tmpl_id.get_product_accounts(fiscal_pos=fpos)
if type == 'in_invoice':
return accounts['stock_input']
@@ -69,7 +69,7 @@ class account_invoice(osv.osv):
inv = i_line.invoice_id
company_currency = inv.company_id.currency_id.id
if i_line.product_id.type in ('product', 'consu') and i_line.product_id.valuation == 'real_time':
if i_line.product_id.type == 'product' and i_line.product_id.valuation == 'real_time':
fpos = i_line.invoice_id.fiscal_position_id
accounts = i_line.product_id.product_tmpl_id.get_product_accounts(fiscal_pos=fpos)
# debit account dacc will be the output account
@@ -200,6 +200,9 @@ class stock_quant(osv.osv):
if move.product_id.valuation != 'real_time':
return False
if move.product_id.type != 'product':
#No stock valuation for consumable products
return False
for q in quants:
if q.owner_id:
#if the quant isn't owned by the company, we don't make any valuation entry
@@ -235,14 +238,12 @@ class stock_quant(osv.osv):
def _quant_create(self, cr, uid, qty, move, lot_id=False, owner_id=False, src_package_id=False, dest_package_id=False, force_location_from=False, force_location_to=False, context=None):
quant = super(stock_quant, self)._quant_create(cr, uid, qty, move, lot_id=lot_id, owner_id=owner_id, src_package_id=src_package_id, dest_package_id=dest_package_id, force_location_from=force_location_from, force_location_to=force_location_to, context=context)
if move.product_id.valuation == 'real_time':
self._account_entry_move(cr, uid, [quant], move, context)
self._account_entry_move(cr, uid, [quant], move, context)
return quant
def move_quants_write(self, cr, uid, quants, move, location_dest_id, dest_package_id, lot_id=False, entire_pack=False, context=None):
res = super(stock_quant, self).move_quants_write(cr, uid, quants, move, location_dest_id, dest_package_id, lot_id=lot_id, entire_pack=entire_pack, context=context)
if move.product_id.valuation == 'real_time':
self._account_entry_move(cr, uid, quants, move, context=context)
self._account_entry_move(cr, uid, quants, move, context=context)
return res
def _get_accounting_data_for_valuation(self, cr, uid, move, context=None):