[REF] purchase, sale_stock, stock_account: some refactoring
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from openerp import SUPERUSER_ID
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.tools.translate import _
|
||||
from openerp.exceptions import UserError
|
||||
@@ -40,7 +39,7 @@ class stock_move(osv.osv):
|
||||
class stock_warehouse(osv.osv):
|
||||
_inherit = 'stock.warehouse'
|
||||
_columns = {
|
||||
'buy_to_resupply': fields.boolean('Purchase to resupply this warehouse',
|
||||
'buy_to_resupply': fields.boolean('Purchase to resupply this warehouse',
|
||||
help="When products are bought, they can be delivered to this warehouse"),
|
||||
'buy_pull_id': fields.many2one('procurement.rule', 'Buy rule'),
|
||||
}
|
||||
|
||||
@@ -258,8 +258,8 @@ class StockPicking(models.Model):
|
||||
class AccountInvoiceLine(models.Model):
|
||||
_inherit = "account.invoice.line"
|
||||
|
||||
def _get_price_unit(self):
|
||||
price_unit = super(AccountInvoiceLine,self)._get_price_unit()
|
||||
def _get_anglo_saxon_price_unit(self):
|
||||
price_unit = super(AccountInvoiceLine,self)._get_anglo_saxon_price_unit()
|
||||
# in case of anglo saxon with a product configured as invoiced based on delivery, with perpetual
|
||||
# valuation and real price costing method, we must find the real price for the cost of good sold
|
||||
uom_obj = self.env['product.uom']
|
||||
|
||||
@@ -27,7 +27,7 @@ class stock_inventory(osv.osv):
|
||||
class account_invoice_line(osv.osv):
|
||||
_inherit = "account.invoice.line"
|
||||
|
||||
def _get_price_unit(self):
|
||||
def _get_anglo_saxon_price_unit(self):
|
||||
self.ensure_one()
|
||||
return self.product_id.standard_price
|
||||
|
||||
@@ -76,7 +76,7 @@ class account_invoice(osv.osv):
|
||||
# credit account cacc will be the expense account
|
||||
cacc = accounts['expense'].id
|
||||
if dacc and cacc:
|
||||
price_unit = i_line._get_price_unit()
|
||||
price_unit = i_line._get_anglo_saxon_price_unit()
|
||||
return [
|
||||
{
|
||||
'type':'src',
|
||||
@@ -88,7 +88,6 @@ class account_invoice(osv.osv):
|
||||
'product_id':i_line.product_id.id,
|
||||
'uom_id':i_line.uom_id.id,
|
||||
'account_analytic_id': False,
|
||||
'taxes':i_line.invoice_line_tax_ids,
|
||||
},
|
||||
|
||||
{
|
||||
@@ -101,7 +100,6 @@ class account_invoice(osv.osv):
|
||||
'product_id':i_line.product_id.id,
|
||||
'uom_id':i_line.uom_id.id,
|
||||
'account_analytic_id': False,
|
||||
'taxes':i_line.invoice_line_tax_ids,
|
||||
},
|
||||
]
|
||||
return []
|
||||
@@ -363,7 +361,7 @@ class stock_move(osv.osv):
|
||||
if any([q.qty <= 0 for q in move.quant_ids]):
|
||||
#if there is a negative quant, the standard price shouldn't be updated
|
||||
return
|
||||
#Note: here we can't store a quant.cost directly as we may have moved out 2 units (1 unit to 5€ and 1 unit to 7€) and in case of a product return of 1 unit, we can't know which of the 2 costs has to be used (5€ or 7€?). So at that time, thanks to the average valuation price we are storing we will svaluate it at 6€
|
||||
#Note: here we can't store a quant.cost directly as we may have moved out 2 units (1 unit to 5€ and 1 unit to 7€) and in case of a product return of 1 unit, we can't know which of the 2 costs has to be used (5€ or 7€?). So at that time, thanks to the average valuation price we are storing we will valuate it at 6€
|
||||
average_valuation_price = 0.0
|
||||
for q in move.quant_ids:
|
||||
average_valuation_price += q.qty * q.cost
|
||||
|
||||
Reference in New Issue
Block a user