diff options
| author | nch@tinyerp.com <> | 2010-05-12 12:17:56 +0530 |
|---|---|---|
| committer | nch@tinyerp.com <> | 2010-05-12 12:17:56 +0530 |
| commit | f0aa8a0a0c1367161eba7426d9a37d61ba8bd899 (patch) | |
| tree | 468357a929cf8584e174458c1ead6f19bee58014 /addons/mrp_procurement/wizard | |
| parent | ce10539ffb5bd18fa2578689f152c88be6966d89 (diff) | |
| parent | bd933e119001332a6eea3255d490a62ccf7fb5fb (diff) | |
[MERGE]
bzr revid: nch@tinyerp.com-20100512064756-778rth7jwjwhcjsz
Diffstat (limited to 'addons/mrp_procurement/wizard')
9 files changed, 481 insertions, 0 deletions
diff --git a/addons/mrp_procurement/wizard/__init__.py b/addons/mrp_procurement/wizard/__init__.py new file mode 100644 index 00000000000..ae70ffbf941 --- /dev/null +++ b/addons/mrp_procurement/wizard/__init__.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +import orderpoint_procurement +import mrp_procurement +import schedulers_all +import make_procurement_product + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/mrp_procurement/wizard/make_procurement_product.py b/addons/mrp_procurement/wizard/make_procurement_product.py new file mode 100644 index 00000000000..96f00b89eb4 --- /dev/null +++ b/addons/mrp_procurement/wizard/make_procurement_product.py @@ -0,0 +1,122 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +import netsvc +import time + +from osv import fields, osv + +class make_procurement(osv.osv_memory): + _name = 'make.procurement' + _description = 'Make Procurements' + + def onchange_product_id(self, cr, uid, ids, prod_id): + """ On Change of Product ID getting the value of related UoM. + @param self: The object pointer. + @param cr: A database cursor + @param uid: ID of the user currently logged in + @param ids: List of IDs selected + @param prod_id: Changed ID of Product + @return: A dictionary which gives the UoM of the changed Product + """ + product = self.pool.get('product.product').browse(cr, uid, prod_id) + return {'value': {'uom_id': product.uom_id.id}} + + _columns = { + 'qty': fields.float('Quantity', digits=(16,2), required=True), + 'product_id': fields.many2one('product.product', 'Product', required=True, readonly=1), + 'uom_id': fields.many2one('product.uom', 'Unit of Measure', required=True), + 'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse', required=True), + 'date_planned': fields.date('Planned Date', required=True), + } + + _defaults = { + 'date_planned': lambda *args: time.strftime('%Y-%m-%d'), + 'qty': lambda *args: 1.0, + } + + def make_procurement(self, cr, uid, ids, context=None): + """ Creates procurement order for selected product. + @param self: The object pointer. + @param cr: A database cursor + @param uid: ID of the user currently logged in + @param ids: List of IDs selected + @param context: A standard dictionary + @return: A dictionary which loads Procurement form view. + """ + user = self.pool.get('res.users').browse(cr, uid, uid, context).login + wh_obj = self.pool.get('stock.warehouse') + procurement_obj = self.pool.get('mrp.procurement') + wf_service = netsvc.LocalService("workflow") + data_obj = self.pool.get('ir.model.data') + + for proc in self.browse(cr, uid, ids): + wh = wh_obj.browse(cr, uid, proc.warehouse_id.id, context) + procure_id = procurement_obj.create(cr, uid, { + 'name':'INT: '+str(user), + 'date_planned': proc.date_planned, + 'product_id': proc.product_id.id, + 'product_qty': proc.qty, + 'product_uom': proc.uom_id.id, + 'location_id': wh.lot_stock_id.id, + 'procure_method':'make_to_order', + }) + + wf_service.trg_validate(uid, 'mrp.procurement', procure_id, 'button_confirm', cr) + + + id2 = data_obj._get_id(cr, uid, 'mrp_procurement', 'mrp_procurement_tree_view') + id3 = data_obj._get_id(cr, uid, 'mrp_procurement', 'mrp_procurement_form_view') + + if id2: + id2 = data_obj.browse(cr, uid, id2, context=context).res_id + if id3: + id3 = data_obj.browse(cr, uid, id3, context=context).res_id + + return { + 'view_type': 'form', + 'view_mode': 'tree,form', + 'res_model': 'mrp.procurement', + 'res_id' : procure_id, + 'views': [(id3,'form'),(id2,'tree')], + 'type': 'ir.actions.act_window', + } + + def default_get(self, cr, uid, fields, context=None): + """ To get default values for the object. + @param self: The object pointer. + @param cr: A database cursor + @param uid: ID of the user currently logged in + @param fields: List of fields for which we want default values + @param context: A standard dictionary + @return: A dictionary which of fields with values. + """ + record_id = context and context.get('active_id', False) or False + + res = super(make_procurement, self).default_get(cr, uid, fields, context=context) + product_id = self.pool.get('product.product').browse(cr, uid, record_id, context=context).id + if 'product_id' in fields: + res.update({'product_id':product_id}) + return res + +make_procurement() +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/addons/mrp_procurement/wizard/make_procurement_view.xml b/addons/mrp_procurement/wizard/make_procurement_view.xml new file mode 100644 index 00000000000..e98f1c013a0 --- /dev/null +++ b/addons/mrp_procurement/wizard/make_procurement_view.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="utf-8"?> +<openerp> + <data> + + <!-- Make Procurement --> + + <record id="view_make_procurment_wizard" model="ir.ui.view"> + <field name="name">Procurement Request</field> + <field name="model">make.procurement</field> + <field name="type">form</field> + <field name="arch" type="xml"> + <form string="Procurement Request"> + <label string="This wizard will plan the procurement for this product. This procurement may generate task, production orders or purchase orders." colspan="4"/> + <field name="product_id" on_change="onchange_product_id(product_id)"/> + <field name="qty"/> + <field name="uom_id"/> + <field name="date_planned"/> + <field name="warehouse_id" colspan="4"/> + <newline/> + <group col="2" colspan="4"> + <button icon='gtk-cancel' special="cancel" + string="Cancel" /> + <button name="make_procurement" string="Ask New Products" + colspan="1" type="object" icon="gtk-ok" /> + </group> + </form> + </field> + </record> + + <act_window name="Procurement Request" + res_model="make.procurement" + src_model="product.product" + view_mode="form" + target="new" + key2="client_action_multi" + id="act_make_procurement" + groups="base.group_extended"/> + + </data> +</openerp> diff --git a/addons/mrp_procurement/wizard/mrp_procurement.py b/addons/mrp_procurement/wizard/mrp_procurement.py new file mode 100644 index 00000000000..1c3f3dd5c8a --- /dev/null +++ b/addons/mrp_procurement/wizard/mrp_procurement.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +import threading +from osv import osv, fields + +class procurement_compute(osv.osv_memory): + _name = 'mrp.procurement.compute' + _description = 'Compute Procurement' + + def _procure_calculation_procure(self, cr, uid, ids, context): + try: + proc_obj = self.pool.get('mrp.procurement') + proc_obj._procure_confirm(cr, uid, use_new_cursor=cr.dbname, context=context) + finally: + cr.close() + return {} + + def procure_calculation(self, cr, uid, ids, context): + """ + @param self: The object pointer. + @param cr: A database cursor + @param uid: ID of the user currently logged in + @param ids: List of IDs selected + @param context: A standard dictionary + """ + threaded_calculation = threading.Thread(target=self._procure_calculation_procure, args=(cr, uid, ids, context)) + threaded_calculation.start() + return {} + +procurement_compute() + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/addons/mrp_procurement/wizard/mrp_procurement_view.xml b/addons/mrp_procurement/wizard/mrp_procurement_view.xml new file mode 100644 index 00000000000..817f7011e0c --- /dev/null +++ b/addons/mrp_procurement/wizard/mrp_procurement_view.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<openerp> + <data> + + <!-- Compute Procurement --> + + <record id="view_compute_procurment_wizard" model="ir.ui.view"> + <field name="name">Compute Procurements</field> + <field name="model">mrp.procurement.compute</field> + <field name="type">form</field> + <field name="arch" type="xml"> + <form string="Parameters"> + <label string="This wizard will schedule procurements." colspan="4" align="0.0"/> + <newline/> + <group col="2" colspan="4"> + <button icon='gtk-cancel' special="cancel" + string="Cancel" /> + <button name="procure_calculation" string="Compute Procurements" + colspan="1" type="object" icon="gtk-ok" /> + </group> + </form> + </field> + </record> + +<!-- <act_window name="Compute Procurements" --> +<!-- res_model="mrp.procurement.compute"--> +<!-- src_model="mrp.procurement"--> +<!-- view_mode="form"--> +<!-- target="new" --> +<!-- key2="client_action_multi" --> +<!-- id="act_compute_procurement"/> --> + + </data> +</openerp> diff --git a/addons/mrp_procurement/wizard/orderpoint_procurement.py b/addons/mrp_procurement/wizard/orderpoint_procurement.py new file mode 100644 index 00000000000..56302660939 --- /dev/null +++ b/addons/mrp_procurement/wizard/orderpoint_procurement.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +# +# Order Point Method: +# - Order if the virtual stock of today is bellow the min of the defined order point +# + +import threading +from osv import fields,osv + +class procurement_compute(osv.osv_memory): + _name = 'mrp.procurement.orderpoint.compute' + _description = 'Automatic Order Point' + + _columns = { + 'automatic': fields.boolean('Automatic Orderpoint', help='If the stock of a product is under 0, it will act like an orderpoint'), + } + + _defaults = { + 'automatic' : lambda *a: False, + } + + def _procure_calculation_orderpoint(self, cr, uid, ids, context): + """ + @param self: The object pointer. + @param cr: A database cursor + @param uid: ID of the user currently logged in + @param ids: List of IDs selected + @param context: A standard dictionary + """ + proc_obj = self.pool.get('mrp.procurement') + for proc in self.browse(cr, uid, ids): + proc_obj._procure_orderpoint_confirm(cr, uid, automatic=proc.automatic, use_new_cursor=cr.dbname, context=context) + + return {} + + def procure_calculation(self, cr, uid, ids, context): + """ + @param self: The object pointer. + @param cr: A database cursor + @param uid: ID of the user currently logged in + @param ids: List of IDs selected + @param context: A standard dictionary + """ + threaded_calculation = threading.Thread(target=self._procure_calculation_orderpoint, args=(cr, uid, ids, context)) + threaded_calculation.start() + return {} + +procurement_compute() + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/mrp_procurement/wizard/orderpoint_procurement_view.xml b/addons/mrp_procurement/wizard/orderpoint_procurement_view.xml new file mode 100644 index 00000000000..c17bedae84f --- /dev/null +++ b/addons/mrp_procurement/wizard/orderpoint_procurement_view.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<openerp> + <data> + + <!-- Compute Stock Minimum Rules Only --> + + <record id="view_procurement_compute_wizard" model="ir.ui.view"> + <field name="name">Compute Stock Minimum Rules Only</field> + <field name="model">mrp.procurement.orderpoint.compute</field> + <field name="type">form</field> + <field name="arch" type="xml"> + <form string="Parameters"> + <field name="automatic"/> + <separator colspan="4"/> + <group col="2" colspan="4"> + <button icon='gtk-cancel' special="cancel" + string="Cancel" /> + <button name="procure_calculation" string="Compute Stock" + colspan="1" type="object" icon="gtk-ok" /> + </group> + </form> + </field> + </record> + + <act_window name="Compute Stock Minimum Rules Only" + res_model="mrp.procurement.orderpoint.compute" + src_model="mrp.procurement" + view_mode="form" + target="new" + key2="client_action_multi" + id="action_procurement_compute"/> + + </data> +</openerp> diff --git a/addons/mrp_procurement/wizard/schedulers_all.py b/addons/mrp_procurement/wizard/schedulers_all.py new file mode 100644 index 00000000000..ad67b1330d0 --- /dev/null +++ b/addons/mrp_procurement/wizard/schedulers_all.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +import threading + +from osv import osv, fields + +class procurement_compute(osv.osv_memory): + _name = 'mrp.procurement.compute.all' + _description = 'Compute all schedulers' + + _columns = { + 'automatic': fields.boolean('Automatic orderpoint',help='Triggers an automatic procurement for all products that have a virtual stock under 0. You should probably not use this option, we suggest using a MTO configuration on products.'), + } + + _defaults ={ + 'automatic': lambda *a: False, + } + + def _procure_calculation_all(self, cr, uid, ids, context): + """ + @param self: The object pointer. + @param cr: A database cursor + @param uid: ID of the user currently logged in + @param ids: List of IDs selected + @param context: A standard dictionary + """ + proc_obj = self.pool.get('mrp.procurement') + for proc in self.browse(cr, uid, ids): + proc_obj.run_scheduler(cr, uid, automatic=proc.automatic, use_new_cursor=cr.dbname,\ + context=context) + return {} + + def procure_calculation(self, cr, uid, ids, context): + """ + @param self: The object pointer. + @param cr: A database cursor + @param uid: ID of the user currently logged in + @param ids: List of IDs selected + @param context: A standard dictionary + """ + threaded_calculation = threading.Thread(target=self._procure_calculation_all, args=(cr, uid, ids, context)) + threaded_calculation.start() + return {} + +procurement_compute() + + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/addons/mrp_procurement/wizard/schedulers_all_view.xml b/addons/mrp_procurement/wizard/schedulers_all_view.xml new file mode 100644 index 00000000000..33861287278 --- /dev/null +++ b/addons/mrp_procurement/wizard/schedulers_all_view.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<openerp> + <data> + + <!-- Compute Schedulers --> + + <record id="view_compute_schedulers_wizard" model="ir.ui.view"> + <field name="name">Compute Schedulers</field> + <field name="model">mrp.procurement.compute.all</field> + <field name="type">form</field> + <field name="arch" type="xml"> + <form string="Scheduler Parameters"> + <field name="automatic"/> + <separator colspan="4"/> + <group col="2" colspan="4"> + <button icon='gtk-cancel' special="cancel" + string="Cancel" /> + <button name="procure_calculation" string="Compute Schedulers" + colspan="1" type="object" icon="gtk-ok" /> + </group> + </form> + </field> + </record> + + <act_window name="Compute Schedulers" + res_model="mrp.procurement.compute.all" + src_model="mrp.procurement" + view_mode="form" + target="new" + key2="client_action_multi" + id="action_compute_schedulers"/> + + </data> +</openerp> |
