1
##############################################################################
3
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
5
# $Id: sale.py 1005 2005-07-25 08:41:42Z nicoe $
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, osv
31
from mx import DateTime
33
class mrp_procurement(osv.osv):
34
_inherit = "mrp.procurement"
36
'production_lot_id':fields.many2one('stock.production.lot', 'Production Lot', relate= True),
37
'customer_ref': fields.char('Customer reference', size=64),
40
def action_po_assign(self, cr, uid, ids):
43
for procurement in self.browse(cr, uid, ids):
44
res_id = procurement.move_id.id
45
partner = procurement.product_id.seller_ids[0].name
46
partner_id = partner.id
47
address_id = self.pool.get('res.partner').address_get(cr, uid, [partner_id], ['delivery'])['delivery']
48
pricelist_id = partner.property_product_pricelist_purchase.id
50
uom_id = procurement.product_id.uom_po_id.id
52
qty = self.pool.get('product.uom')._compute_qty(cr, uid, procurement.product_uom.id, procurement.product_qty, uom_id)
53
if procurement.product_id.seller_ids[0].qty:
54
qty=max(qty,procurement.product_id.seller_ids[0].qty)
56
price = self.pool.get('product.pricelist').price_get(cr, uid, [pricelist_id], procurement.product_id.id, qty, False, {'uom': uom_id})[pricelist_id]
58
newdate = DateTime.strptime(procurement.date_planned, '%Y-%m-%d') - DateTime.RelativeDateTime(days=procurement.product_id.product_tmpl_id.seller_delay or 0.0)
60
'name': procurement.product_id.name[:50],
62
'product_id': procurement.product_id.id,
63
'product_uom': uom_id,
65
'date_planned': newdate.strftime('%Y-%m-%d'),
66
'taxes_id': [(6, 0, [x.id for x in procurement.product_id.product_tmpl_id.taxes_id])],
67
'move_dest_id': res_id,
69
'production_lot_id': procurement.production_lot_id.id,
70
'customer_ref': procurement.customer_ref,
72
purchase_id = self.pool.get('purchase.order').create(cr, uid, {
73
'origin': procurement.origin,
74
'partner_id': partner_id,
75
'partner_address_id': address_id,
76
'location_id': procurement.location_id.id,
77
'pricelist_id': pricelist_id,
78
'order_line': [(0,0,line)],
79
'invoice_method':'manual',
81
self.write(cr, uid, [procurement.id], {'state':'running', 'purchase_id':purchase_id})