-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
23 lines (22 loc) · 1.2 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# -*- coding: utf-8 -*-
from openerp.osv import fields, osv
from openerp.tools.float_utils import float_compare, float_round
import openerp.addons.decimal_precision as dp
class stock_quant(osv.osv):
_inherit = "stock.quant"
def _calc_unit_value(self, cr, uid, ids, name, attr, context=None):
context = dict(context or {})
res = {}
uid_company_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
for quant in self.browse(cr, uid, ids, context=context):
context.pop('force_company', None)
if quant.company_id.id != uid_company_id:
#if the company of the quant is different than the current user company, force the company in the context
#then re-do a browse to read the property fields for the good company.
context['force_company'] = quant.company_id.id
quant = self.browse(cr, uid, quant.id, context=context)
res[quant.id] = self._get_inventory_value(cr, uid, quant, context=context)/quant.qty
return res
_columns = {
'unit_price': fields.function(_calc_unit_value, string="Pret unitar", type='float', readonly=True),
}