1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). All Rights Reserved.
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (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 General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
23
Auxiliary object to mate products with structural costs
26
from osv import osv, fields
28
import decimal_precision as dp
30
from tools.translate import _
32
class product_percent_struct_costs(osv.osv_memory):
34
Auxiliar object to associate percentually costs to products
36
def onchange_product_id(self, cr, uid, ids, prev_fyear_id, prev_period_id, product_id):
38
Gets total sales for this product, fiscal year and period
42
sales_facade = self.pool.get('sale.order')
43
fiscalyear = self.pool.get('account.fiscalyear').browse(cr, uid, prev_fyear_id)
44
if not prev_period_id:
45
from_date =fiscalyear.date_start
46
to_date = fiscalyear.date_stop
48
period = self.pool.get('account.period').browse(cr, uid, prev_period_id)
49
from_date = period.date_start
50
to_date = period.date_stop
52
period_sales = sales_facade.browse(cr, uid, sales_facade.search(cr, uid, [('state','not in',['draft','cancel']),('date_order','<=', to_date), ('date_order','>=', from_date)]))
53
for sale in period_sales:
54
for line in sale.order_line:
56
if line.product_id.id == product_id:
57
total_sales += line.product_uom_qty
59
res['total_sales'] = total_sales
60
res['forecasted_sales'] = total_sales
65
def onchange_total_sales(self, cr, uid, ids, total_sales):
67
Refresh forecasted values according total sales
71
res['forecasted_sales'] = total_sales
73
res['forecasted_sales'] = 0.0
77
_name = 'product.percent.struct.costs'
78
_description = 'Structural products cost'
80
'product_id': fields.many2one('product.product','Product',required=True),
81
'total_sales': fields.float('Sold Units', digits_compute=dp.get_precision('Account'), required=True),
82
'forecasted_sales': fields.float('Forecasted Sold Units', digits_compute=dp.get_precision('Account')),
83
'wizard_id': fields.many2one('structural.costs.impact.wizard','Wizard'),
87
'wizard_id': lambda self, cr, uid, context: context.get('parent_id') and context['parent_id'] or False,
91
product_percent_struct_costs()
b'\\ No newline at end of file'