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 ##############################################################################
28 def _get_default(obj, cr, uid, data, context=None):
29 pool = pooler.get_pool(cr.dbname)
30 product = pool.get('product.product').browse(cr, uid, data['id'], context)
31 return {'product_id': product.id, 'uom_id':product.uom_id.id, 'qty':1.0}
33 def make_procurement(obj, cr, uid, data, context=None):
34 '''Create procurement'''
35 pool = pooler.get_pool(cr.dbname)
36 wh = pool.get('stock.warehouse').browse(cr, uid, data['form']['warehouse_id'], context)
37 user = pool.get('res.users').browse(cr, uid, uid, context)
38 procure_id = pool.get('mrp.procurement').create(cr, uid, {
39 'name':'INT:'+str(user.login),
40 'date_planned':data['form']['date_planned'],
41 'product_id':data['form']['product_id'],
42 'product_qty':data['form']['qty'],
43 'product_uom':data['form']['uom_id'],
44 'location_id':wh.lot_stock_id.id,
45 'procure_method':'make_to_order',
47 wf_service = netsvc.LocalService("workflow")
48 wf_service.trg_validate(uid, 'mrp.procurement', procure_id, 'button_confirm', cr)
52 class MakeProcurement(wizard.interface):
53 '''Wizard that create a procurement from a product form'''
55 done_form = """<?xml version="1.0"?>
56 <form string="Make Requisition">
57 <label string="Your procurement request has been sent !"/>
59 procurement_form = """<?xml version="1.0"?>
60 <form string="Internal Requisition Request">
61 <label string="This wizard will plan the procurement for this product. This procurement may generate task, production orders or purchase orders." align="0.0" colspan="4"/>
62 <field name="product_id"/>
63 <field name="warehouse_id"/>
65 <field name="uom_id"/>
66 <field name="date_planned"/>
68 procurement_fields = {
69 'qty': {'string': 'Quantity', 'type': 'float', 'digits':(16,2), 'required': True},
70 'product_id': {'string': 'product', 'type': 'many2one', 'relation': 'product.product', 'required': True, 'readonly':1},
71 'uom_id': {'string': 'Unit of Measure', 'type': 'many2one', 'relation': 'product.uom', 'required':True},
72 'warehouse_id': {'string': 'Warehouse', 'type': 'many2one', 'relation':'stock.warehouse', 'required':True},
73 'date_planned': {'string': 'Planned Date', 'type': 'date', 'required':True, 'default': lambda *args: time.strftime('%Y-%m-%d')}
78 'actions': [_get_default],
79 'result': {'type': 'form', 'arch': procurement_form, 'fields': procurement_fields,
82 ('create', 'Ask New Products')
88 'result': {'type': 'form', 'arch': done_form, 'fields': {},
96 'result': {'type': 'action', 'action': make_procurement, 'state': 'done'}
100 MakeProcurement('product.product.procurement')
101 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: