1
##############################################################################
3
# Copyright (c) 2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
7
# WARNING: This program as such is intended to be used by professional
8
# programmers who take the whole responsability of assessing all potential
9
# consequences resulting from its eventual inadequacies and bugs
10
# End users who are looking for a ready-to-use solution with commercial
11
# garantees and support are strongly adviced to contract a Free Software
14
# This program is Free Software; you can redistribute it and/or
15
# modify it under the terms of the GNU General Public License
16
# as published by the Free Software Foundation; either version 2
17
# of the License, or (at your option) any later version.
19
# This program is distributed in the hope that it will be useful,
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
# GNU General Public License for more details.
24
# You should have received a copy of the GNU General Public License
25
# along with this program; if not, write to the Free Software
26
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
##############################################################################
30
from osv import fields
35
class product_supplierinfo(osv.osv):
36
_inherit = 'product.supplierinfo'
37
_name = "product.supplierinfo"
39
def _last_order(self, cr, uid, ids, name, arg, context):
41
for supinfo in self.browse(cr, uid, ids):
42
cr.execute("select po.id, max(po.date_approve) from purchase_order as po, purchase_order_line as line where po.id=line.order_id and product_id=%d and partner_id=%d and state='approved' group by po.id", (supinfo.product_id.id, supinfo.name.id,))
43
record = cr.fetchone()
45
res[supinfo.id] = record[0]
47
res[supinfo.id] = False
50
def _last_order_date(self, cr, uid, ids, name, arg, context):
52
po = self.pool.get('purchase.order')
53
last_orders = self._last_order(cr, uid, ids, name, arg, context)
54
dates = po.read(cr, uid, filter(None, last_orders.values()), ['date_approve'])
56
date_approve = [x['date_approve'] for x in dates if x['id']==last_orders[suppinfo]]
58
res[suppinfo] = date_approve[0]
64
'last_order' : fields.function(_last_order, type='many2one', obj='purchase.order', method=True, string='Last Order'),
65
'last_order_date' : fields.function(_last_order_date, type='date', method=True, string='Last Order date'),
67
product_supplierinfo()
70
class product_product(osv.osv):
71
_name = 'product.product'
72
_inherit = 'product.product'
74
def _find_op(self, cr, uid, ids, name, arg, context):
76
for product_id in ids:
77
cr.execute('SELECT swo.id from stock_warehouse_orderpoint AS swo WHERE product_id=%d', (product_id,))
80
res[product_id] = op_id[0]
82
res[product_id] = False
85
def _product_dispo(self, cr, uid, ids, name, arg, context={}):
87
out = self._product_outgoing_qty(cr, uid, ids, name, arg, context)
88
now = self._product_qty_available(cr, uid, ids, name, arg, context)
90
res[p_id] = now[p_id] + out[p_id]
95
'calculate_price': fields.boolean('Compute price'),
96
'orderpoint_ids': fields.one2many('stock.warehouse.orderpoint', 'product_id', 'Orderpoints'),
97
'qty_dispo': fields.function(_product_dispo, method=True, type='float', string='Stock disponible'),
101
'calculate_price': lambda w,x,y,z: False,
104
def compute_price(self, cr, uid, ids, *args):
106
bom_ids = pooler.get_pool(cr.dbname).get('mrp.bom').search(cr, uid, [('product_id', '=', prod_id)])
108
for bom in pooler.get_pool(cr.dbname).get('mrp.bom').browse(cr, uid, bom_ids):
109
self._calc_price(cr, uid, bom)
112
def _calc_price(self, cr, uid, bom):
113
if not bom.product_id.calculate_price:
114
return bom.product_id.standard_price
118
for sbom in bom.bom_lines:
119
price += self._calc_price(cr, uid, sbom) * sbom.product_qty
121
bom_obj = pooler.get_pool(cr.dbname).get('mrp.bom')
122
no_child_bom = bom_obj.search(cr, uid, [('product_id', '=', bom.product_id.id), ('bom_id', 'is', None)])
124
other_bom = bom_obj.browse(cr, uid, no_child_bom)[0]
125
price += bom.product_qty * self._calc_price(cr, uid, other_bom)
126
elif bom.product_id.seller_ids:
127
pricelist_id = bom.product_id.seller_ids[0].name.property_product_pricelist_purchase[0]
128
price += pooler.get_pool(cr.dbname).get('product.pricelist').price_get(cr, uid, [pricelist_id], bom.product_id.id, bom.product_qty, 'standard')[pricelist_id]
130
price += bom.product_qty * bom.product_id.standard_price
133
for wline in bom.routing_id.workcenter_lines:
134
wc = wline.workcenter_id
135
cycle = wline.cycle_nbr
136
hour = (wc.time_start + wc.time_stop + cycle * wc.time_cycle) * (wc.time_efficiency or 1.0)
137
price += wc.costs_cycle * cycle + wc.costs_hour * hour
139
self.write(cr, uid, [bom.product_id.id], {'standard_price' : price})