~openerp-commiter/openobject-addons/trunk-extra-addons

« back to all changes in this revision

Viewing changes to library/mrp.py

  • Committer: Mustufa Rangwala
  • Date: 2008-06-11 07:23:21 UTC
  • Revision ID: mra@tinyerp.com-1f024e3ce89987454b17eeada86984fede80dbad
* it defines access rules on crm object
        - some groups only can see the confidential info..
        - it defines some rules on created groups

* based on crm module

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#
 
5
# $Id: sale.py 1005 2005-07-25 08:41:42Z nicoe $
 
6
#
 
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
 
12
# Service Company
 
13
#
 
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.
 
18
#
 
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.
 
23
#
 
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.
 
27
#
 
28
##############################################################################
 
29
 
 
30
from osv import fields, osv
 
31
from mx import DateTime
 
32
 
 
33
class mrp_procurement(osv.osv):
 
34
        _inherit = "mrp.procurement"
 
35
        _columns = {
 
36
                'production_lot_id':fields.many2one('stock.production.lot', 'Production Lot', relate= True),
 
37
                'customer_ref': fields.char('Customer reference', size=64),             
 
38
 }
 
39
 
 
40
        def action_po_assign(self, cr, uid, ids):
 
41
                purchase_id = False
 
42
 
 
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
 
49
 
 
50
                        uom_id = procurement.product_id.uom_po_id.id
 
51
 
 
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)
 
55
 
 
56
                        price = self.pool.get('product.pricelist').price_get(cr, uid, [pricelist_id], procurement.product_id.id, qty, False, {'uom': uom_id})[pricelist_id]
 
57
 
 
58
                        newdate = DateTime.strptime(procurement.date_planned, '%Y-%m-%d') - DateTime.RelativeDateTime(days=procurement.product_id.product_tmpl_id.seller_delay or 0.0)
 
59
                        line = {
 
60
                                'name': procurement.product_id.name[:50],
 
61
                                'product_qty': qty,
 
62
                                'product_id': procurement.product_id.id,
 
63
                                'product_uom': uom_id,
 
64
                                'price_unit': price,
 
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,
 
68
                                #added
 
69
                                'production_lot_id': procurement.production_lot_id.id,
 
70
                                'customer_ref': procurement.customer_ref,
 
71
                        }
 
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',
 
80
                        })
 
81
                        self.write(cr, uid, [procurement.id], {'state':'running', 'purchase_id':purchase_id})
 
82
                return purchase_id
 
83
 
 
84
mrp_procurement()
 
85