1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
23
from datetime import datetime
26
from openerp import tools
27
from openerp.osv import osv, fields
28
from openerp.tools.translate import _
30
import openerp.addons.decimal_precision as dp
34
class product_cost_multicompany(osv.osv):
35
_name = "product.cost_multicompany"
36
_description = "Product Cost Multicompany"
38
_rec_name = "product_id"
41
'product_id' : fields.many2one('product.product', 'Product', required=True, select=True),
42
'company_id' : fields.many2one('res.company', 'Company', required=True, select=True),
43
'standard_price' : fields.float('Cost', digits_compute=dp.get_precision('Product Price'), help="Cost price of the product", groups="base.group_user"),
47
'standard_price': 0.0,
50
_order = "company_id, product_id"
53
('product_company_uniq', 'unique(company_id, product_id)', 'The product cost must be unique per company!'),
56
class product_product(osv.osv):
57
_inherit = 'product.product'
59
def _get_standard_price(self, cr, uid, ids, name, arg, context=None):
63
for p in self.browse(cr, uid, ids, context=context):
64
#if p.cost_method == 'standard':
65
# res[p.id] = p.standard_price2
67
product_price_obj = self.pool.get('product.cost_multicompany')
68
price_id = product_price_obj.search(cr, uid, [('product_id','=',ids[0]), ('company_id','=',self.pool.get('res.users').browse(cr, uid, uid).company_id.id)])
69
res[p.id] = product_price_obj.read(cr, uid, price_id)[0]['standard_price'] if price_id else 0.0
73
'standard_prices' : fields.one2many('product.cost_multicompany', 'product_id', string="Standard Price"),
74
'standard_price' : fields.function(_get_standard_price, type='float', string='Cost', digits_compute=dp.get_precision('Product Price'), help="Cost price of the product used for standard stock valuation in accounting and used as a base price on purchase orders.", groups="base.group_user"),
77
def write(self, cr, uid, ids, vals, context=None):
80
if 'standard_price' in xvals:
81
company_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.id
82
product_price_obj = self.pool.get('product.cost_multicompany')
83
price_id = product_price_obj.search(cr, uid, [('product_id','=',ids[0]), ('company_id','=',company_id)])
85
product_price_obj.write(cr, uid, price_id, {'standard_price': xvals['standard_price']})
87
res = product_price_obj.create(cr, uid, {'company_id' : company_id, 'product_id' : ids[0], 'standard_price' : xvals['standard_price']})
88
return super(product_product, self).write(cr, uid, ids, xvals, context=context)
92
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: