summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruco (OpenERP) <uco@tinyerp.co.in>2010-03-09 13:12:38 +0530
committeruco (OpenERP) <uco@tinyerp.co.in>2010-03-09 13:12:38 +0530
commit9fd8b8ad5a477a1a3b2eba88267d2dad48e64741 (patch)
treee5271ddf553ea9f2d4705064c89c6c1ccf934d1f
parent8c6e6f721324b438721a26f06b87c5aab507019e (diff)
[IMP] mrp: Converted 'Change Production Quantity' wizard into osv_memory wizard.
bzr revid: uco@tinyerp.co.in-20100309074238-9qher5ex154s3hlb
-rw-r--r--addons/mrp/__terp__.py3
-rw-r--r--addons/mrp/mrp_view.xml16
-rw-r--r--addons/mrp/wizard/__init__.py2
-rw-r--r--addons/mrp/wizard/change_production_qty.py87
-rw-r--r--addons/mrp/wizard/change_production_qty_view.xml45
-rw-r--r--addons/mrp/wizard/wizard_change_production_qty.py117
6 files changed, 143 insertions, 127 deletions
diff --git a/addons/mrp/__terp__.py b/addons/mrp/__terp__.py
index 9f5bc664be7..ff51c74a41a 100644
--- a/addons/mrp/__terp__.py
+++ b/addons/mrp/__terp__.py
@@ -61,8 +61,9 @@
'mrp_workflow.xml',
'mrp_data.xml',
'mrp_wizard_view.xml',
- 'mrp_view.xml',
'wizard/make_procurement_view.xml',
+ 'wizard/change_production_qty_view.xml',
+ 'mrp_view.xml',
'mrp_wizard.xml',
'mrp_report.xml',
'company_view.xml',
diff --git a/addons/mrp/mrp_view.xml b/addons/mrp/mrp_view.xml
index 6041bc5163c..061278771db 100644
--- a/addons/mrp/mrp_view.xml
+++ b/addons/mrp/mrp_view.xml
@@ -440,13 +440,13 @@
</field>
</record>
- <wizard
- string="Change Product Qty."
- model="mrp.production"
- name="change_production_qty"
- id="mrp.wizard_change_production_qty"
- keyword="client_action_multi"
- multi="True"/>
+<!-- <wizard-->
+<!-- string="Change Product Qty."-->
+<!-- model="mrp.production"-->
+<!-- name="change_production_qty"-->
+<!-- id="mrp.wizard_change_production_qty"-->
+<!-- keyword="client_action_multi"-->
+<!-- multi="True"/>-->
<record id="mrp_production_form_view" model="ir.ui.view">
<field name="name">mrp.production.form</field>
@@ -462,7 +462,7 @@
<field name="product_qty"/>
<group colspan="2" col="3">
<field name="product_uom"/>
- <button type="action" name="%(mrp.wizard_change_production_qty)d" string="Change Qty" states="ready,confirmed,in_production"/>
+ <button type="action" name="%(mrp.action_change_production_qty)d" string="Change Qty" states="ready,confirmed,in_production"/>
</group>
<label string="" colspan="2"/>
<field name="product_uos_qty" groups="product.group_uos"/>
diff --git a/addons/mrp/wizard/__init__.py b/addons/mrp/wizard/__init__.py
index a859d55b44e..462ec509e09 100644
--- a/addons/mrp/wizard/__init__.py
+++ b/addons/mrp/wizard/__init__.py
@@ -25,7 +25,7 @@ import wizard_schedulers_all
import wizard_price
import wizard_workcenter_load
import wizard_track_prod
-import wizard_change_production_qty
+import change_production_qty
import make_procurement_product
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/mrp/wizard/change_production_qty.py b/addons/mrp/wizard/change_production_qty.py
new file mode 100644
index 00000000000..56fd5fc2b53
--- /dev/null
+++ b/addons/mrp/wizard/change_production_qty.py
@@ -0,0 +1,87 @@
+# -*- 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 time
+import ir
+from osv.osv import except_osv
+from osv import fields, osv
+import netsvc
+from tools.translate import _
+
+class change_production_qty(osv.osv_memory):
+ _name = 'change.production.qty'
+ _description = 'Change Quantity of Products'
+
+ _columns = {
+ 'product_qty': fields.float('Product Qty', required=True),
+ }
+
+ def default_get(self, cr, uid, ids, context):
+ record_id = context and context.get('record_id',False)
+ res = {}
+ prod_obj = self.pool.get('mrp.production')
+ prod = prod_obj.browse(cr, uid, record_id)
+ if prod.state in ('cancel', 'done'):
+ raise osv.except_osv(_('Warning !'), _('The production is in "%s" state. You can not change the production quantity anymore') % (prod.state).upper() )
+ if prod.state in ('draft'):
+ return res
+ if record_id:
+ res['product_qty'] = prod.product_qty
+ return res
+
+ def change_prod_qty(self, cr, uid, ids, context):
+ record_id = context and context.get('record_id',False)
+ prod_obj = self.pool.get('mrp.production')
+ wiz_qty = self.browse(cr, uid, ids[0])
+ prod = prod_obj.browse(cr, uid,record_id)
+ prod_obj.write(cr, uid,prod.id, {'product_qty': wiz_qty.product_qty})
+ prod_obj.action_compute(cr, uid, [prod.id])
+
+ move_lines_obj = self.pool.get('stock.move')
+ for move in prod.move_lines:
+ bom_point = prod.bom_id
+ bom_id = prod.bom_id.id
+ if not bom_point:
+ bom_id = self.pool.get('mrp.bom')._bom_find(cr, uid, prod.product_id.id, prod.product_uom.id)
+ if not bom_id:
+ raise osv.except_osv(_('Error'), _("Couldn't find bill of material for product"))
+ prod_obj.write(cr, uid, [prod.id], {'bom_id': bom_id})
+ bom_point = self.pool.get('mrp.bom').browse(cr, uid, [bom_id])[0]
+
+ if not bom_id:
+ raise osv.except_osv(_('Error'), _("Couldn't find bill of material for product"))
+
+ factor = prod.product_qty * prod.product_uom.factor / bom_point.product_uom.factor
+ res = self.pool.get('mrp.bom')._bom_explode(cr, uid, bom_point, factor / bom_point.product_qty, [])
+ for r in res[0]:
+ if r['product_id']== move.product_id.id:
+ move_lines_obj.write(cr, uid,move.id, {'product_qty' : r['product_qty']})
+
+ product_lines_obj = self.pool.get('mrp.production.product.line')
+
+ for m in prod.move_created_ids:
+ move_lines_obj.write(cr, uid,m.id, {'product_qty': wiz_qty.product_qty})
+
+ return {}
+
+change_production_qty()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/mrp/wizard/change_production_qty_view.xml b/addons/mrp/wizard/change_production_qty_view.xml
new file mode 100644
index 00000000000..8b0e5ffd021
--- /dev/null
+++ b/addons/mrp/wizard/change_production_qty_view.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+ <data>
+
+ <!-- Change Product Quantity -->
+
+ <record id="view_change_production_qty_wizard" model="ir.ui.view">
+ <field name="name">Change Product Qty</field>
+ <field name="model">change.production.qty</field>
+ <field name="type">form</field>
+ <field name="arch" type="xml">
+ <form string="Change Product Qty">
+ <field name="product_qty"/>
+ <newline/>
+ <group col="2" colspan="4">
+ <button icon='gtk-cancel' special="cancel"
+ string="Cancel" />
+ <button name="change_prod_qty" string="Validate"
+ colspan="1" type="object" icon="gtk-ok" />
+ </group>
+ </form>
+ </field>
+ </record>
+
+ <record id="action_change_production_qty" model="ir.actions.act_window">
+ <field name="name">Change Product Qty</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">change.production.qty</field>
+ <field name="view_type">form</field>
+ <field name="view_mode">form</field>
+ <field name="target">new</field>
+ <field name="context">{'record_id' : active_id}</field>
+ </record>
+
+ <record model="ir.values" id="values_change_production_qty">
+ <field name="model_id" ref="mrp.model_mrp_production" />
+ <field name="object" eval="1" />
+ <field name="name">Change Product Qty</field>
+ <field name="key2">client_action_multi</field>
+ <field name="value" eval="'ir.actions.act_window,' + str(ref('action_change_production_qty'))"/>
+ <field name="key">action</field>
+ <field name="model">mrp.production</field>
+ </record>
+ </data>
+</openerp>
diff --git a/addons/mrp/wizard/wizard_change_production_qty.py b/addons/mrp/wizard/wizard_change_production_qty.py
deleted file mode 100644
index a9a8387acdf..00000000000
--- a/addons/mrp/wizard/wizard_change_production_qty.py
+++ /dev/null
@@ -1,117 +0,0 @@
-# -*- 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 time
-import wizard
-import ir
-import pooler
-from osv.osv import except_osv
-from osv import fields,osv
-import netsvc
-from tools.translate import _
-
-
-form1 = '''<?xml version="1.0"?>
-<form string="Change Product Qty">
- <field name="product_qty"/>
-</form>'''
-
-form1_fields={
- 'product_qty': {'string': 'Product Qty', 'type':'float', 'required':True},
- }
-
-def _get_qty(self,cr,uid, data, state):
- prod_obj = pooler.get_pool(cr.dbname).get('mrp.production')
- prod = prod_obj.browse(cr, uid,data['ids'])[0]
- form1_fields['product_qty']['default']=prod.product_qty
- return {}
-def _get_states(self, cr, uid, data, context):
- prod_obj = pooler.get_pool(cr.dbname).get('mrp.production')
- prod = prod_obj.browse(cr, uid,data['ids'])[0]
- if prod.state in ('cancel', 'done'):
- raise wizard.except_wizard(_('Warning !'), _('The production is in "%s" state. You can not change the production quantity anymore') % (prod.state).upper() )
- return 'end'
- if prod.state in ('draft'):
- #raise wizard.except_wizard('Warning !', 'The production is in "%s" state. You can change the production quantity directly...!!!' % (prod.state).upper() )
- return 'end'
- else:
- return 'confirm'
-
-def _change_prod_qty(self, cr, uid, data, context):
- pool = pooler.get_pool(cr.dbname)
- prod_obj = pool.get('mrp.production')
- prod = prod_obj.browse(cr, uid,data['ids'])[0]
- prod_obj.write(cr, uid,prod.id, {'product_qty' : data['form']['product_qty']})
- prod_obj.action_compute(cr, uid, [prod.id])
-
- move_lines_obj = pool.get('stock.move')
- for move in prod.move_lines:
- bom_point = prod.bom_id
- bom_id = prod.bom_id.id
- if not bom_point:
- bom_id = pool.get('mrp.bom')._bom_find(cr, uid, prod.product_id.id, prod.product_uom.id)
- if not bom_id:
- raise osv.except_osv(_('Error'), _("Couldn't find bill of material for product"))
- self.write(cr, uid, [prod.id], {'bom_id': bom_id})
- bom_point = pool.get('mrp.bom').browse(cr, uid, [bom_id])[0]
-
- if not bom_id:
- raise osv.except_osv(_('Error'), _("Couldn't find bill of material for product"))
-
- factor = prod.product_qty * prod.product_uom.factor / bom_point.product_uom.factor
- res = pool.get('mrp.bom')._bom_explode(cr, uid, bom_point, factor / bom_point.product_qty, [])
- for r in res[0]:
- if r['product_id']== move.product_id.id:
- move_lines_obj.write(cr, uid,move.id, {'product_qty' : r['product_qty']})
-
- product_lines_obj = pool.get('mrp.production.product.line')
-
- for m in prod.move_created_ids:
- move_lines_obj.write(cr, uid,m.id, {'product_qty' : data['form']['product_qty']})
-
- return {}
-
-class change_production_qty(wizard.interface):
- states = {
- 'init' : {
- 'actions' : [],
- 'result' : {'type' : 'choice', 'next_state' : _get_states}
- },
-
- 'confirm' : {
- 'actions' : [_get_qty],
- 'result': {'type': 'form', 'arch':form1, 'fields':form1_fields, 'state':[('end','Cancel'),('validate','Validate')]}
- },
-
- 'validate': {
- 'actions': [],
- 'result': {'type':'action', 'action':_change_prod_qty, 'state':'end'}
- },
-
- 'end' : {
- 'actions' : [],
- 'result': {'type': 'state', 'state': 'end'},
- },
- }
-
-change_production_qty('change_production_qty')
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: