45 lines
1.9 KiB
Python
45 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo import api, fields, models
|
|
|
|
class StockQuant(models.Model):
|
|
_inherit = 'stock.quant'
|
|
|
|
@api.depends_context('company')
|
|
@api.depends('product_categ_id.property_cost_method')
|
|
def _compute_cost_method(self):
|
|
for quant in self:
|
|
quant.cost_method = (
|
|
quant.product_categ_id.sudo().with_company(
|
|
quant.company_id
|
|
).property_cost_method
|
|
or (quant.company_id or self.env.company).cost_method
|
|
)
|
|
|
|
@api.depends('company_id', 'location_id', 'owner_id', 'product_id', 'quantity')
|
|
def _compute_value(self):
|
|
self.fetch(['company_id', 'location_id', 'owner_id', 'product_id', 'quantity', 'lot_id'])
|
|
self.value = 0
|
|
for quant in self:
|
|
if not quant.location_id or not quant.product_id or\
|
|
not quant.location_id._should_be_valued() or\
|
|
quant._should_exclude_for_valuation() or\
|
|
quant.product_id.uom_id.is_zero(quant.quantity):
|
|
continue
|
|
if quant.product_id.lot_valuated:
|
|
quantity = quant.lot_id.sudo().with_company(quant.company_id).product_qty
|
|
value = quant.lot_id.sudo().with_company(quant.company_id).total_value
|
|
else:
|
|
quantity = quant.product_id.sudo().with_company(quant.company_id)._with_valuation_context().qty_available
|
|
value = quant.product_id.sudo().with_company(quant.company_id).total_value
|
|
if quant.product_id.uom_id.is_zero(quantity):
|
|
continue
|
|
quant.value = quant.quantity * value / quantity
|
|
|
|
class StockMove(models.Model):
|
|
_inherit = 'stock.move'
|
|
|
|
@api.depends('product_id.standard_price')
|
|
def _compute_standard_price(self):
|
|
for move in self:
|
|
move.standard_price = move.product_id.sudo().with_company(move.company_id).standard_price
|