diff options
| author | pinky <> | 2006-12-07 13:41:40 +0000 |
|---|---|---|
| committer | pinky <> | 2006-12-07 13:41:40 +0000 |
| commit | a83dce15e0f33145b2eea7e878ae7eacf3aba90a (patch) | |
| tree | a3d1399cbfebf7d90a8894d97c9b7e0a9d881960 /addons/mrp/wizard | |
| parent | 004a0b996ff8f269451e07346f71a129a1f3fbaf (diff) | |
New trunk
bzr revid: pinky-dedd7f8a42bd4557112a0513082691b8590ad6cc
Diffstat (limited to 'addons/mrp/wizard')
| -rw-r--r-- | addons/mrp/wizard/__init__.py | 34 | ||||
| -rw-r--r-- | addons/mrp/wizard/schedulers.py | 199 | ||||
| -rw-r--r-- | addons/mrp/wizard/wizard_orderpoint_procurement.py | 74 | ||||
| -rw-r--r-- | addons/mrp/wizard/wizard_price.py | 54 | ||||
| -rw-r--r-- | addons/mrp/wizard/wizard_procurement.py | 74 | ||||
| -rw-r--r-- | addons/mrp/wizard/wizard_schedulers_all.py | 79 | ||||
| -rw-r--r-- | addons/mrp/wizard/wizard_track_prod.py | 109 | ||||
| -rw-r--r-- | addons/mrp/wizard/wizard_workcenter_load.py | 55 |
8 files changed, 678 insertions, 0 deletions
diff --git a/addons/mrp/wizard/__init__.py b/addons/mrp/wizard/__init__.py new file mode 100644 index 00000000000..0e515d862c2 --- /dev/null +++ b/addons/mrp/wizard/__init__.py @@ -0,0 +1,34 @@ +############################################################################## +# +# Copyright (c) 2005-2005 TINY SPRL. (http://tiny.be) All Rights Reserved. +# Fabien Pinckaers <fp@tiny.Be> +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +import wizard_orderpoint_procurement +import wizard_procurement +import wizard_schedulers_all +import wizard_price +import wizard_workcenter_load +import wizard_track_prod diff --git a/addons/mrp/wizard/schedulers.py b/addons/mrp/wizard/schedulers.py new file mode 100644 index 00000000000..f44b8f14085 --- /dev/null +++ b/addons/mrp/wizard/schedulers.py @@ -0,0 +1,199 @@ +############################################################################## +# +# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. +# +# $Id$ +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +import pooler +import time +from mx import DateTime +import netsvc +from osv import osv + +def _procure_confirm(self, db_name, uid, data, context): + cr = pooler.get_db(db_name).cursor() + + wf_service = netsvc.LocalService("workflow") + + cr.execute('select id from mrp_procurement where state=%s order by date_planned', ('exception',)) + ids = map(lambda x:x[0], cr.fetchall()) + for id in ids: + wf_service.trg_validate(uid, 'mrp.procurement', id, 'button_restart', cr) + cr.commit() + + po_time = (data['form']['po_cycle'] or 0.0) + (data['form']['po_lead'] or 0.0) + maxdate = DateTime.now() + DateTime.RelativeDateTime(days=(data['form']['schedule_cycle'] or 0.0) + (data['form']['security_lead'] or 0.0)) + start_date = time.strftime('%Y-%m-%d, %Hh %Mm %Ss') + offset = 0 + report = [] + report_total = 0 + report_except = 0 + report_later = 0 + ids = [1] + while len(ids): + cr.execute('select id from mrp_procurement where state=%s and procure_method=%s order by date_planned limit 500 offset %d', ('confirmed','make_to_order',offset)) + ids = map(lambda x:x[0], cr.fetchall()) + for proc in pooler.get_pool(cr.dbname).get('mrp.procurement').browse(cr, uid, ids): + if proc.product_id.supply_method=='produce': + wf_service.trg_validate(uid, 'mrp.procurement', proc.id, 'button_check', cr) + else: + if (maxdate + DateTime.RelativeDateTime(days=(proc.product_id.seller_delay or 0 + po_time))).strftime('%Y-%m-%d')>=proc.date_planned: + wf_service.trg_validate(uid, 'mrp.procurement', proc.id, 'button_check', cr) + else: + offset+=1 + report_later += 1 + cr.execute('select name,state from mrp_procurement where id=%d', (proc.id,)) + name,state = cr.fetchone() + if state=='exception': + report.append('PROC %d: MTO - %3d %-5s - %s' % (proc.id,proc.product_qty,proc.product_uom.name, proc.product_id.name)) + report_except += 1 + report_total +=1 + cr.commit() + + offset = 0 + ids = [1] + while len(ids): + ids = pooler.get_pool(cr.dbname).get('mrp.procurement').search(cr, uid, [('state','=','confirmed'),('procure_method','=','make_to_stock')], offset=offset) + for proc in pooler.get_pool(cr.dbname).get('mrp.procurement').browse(cr, uid, ids): + if (maxdate + DateTime.RelativeDateTime(days=data['form']['picking_lead'])).strftime('%Y-%m-%d') >= proc.date_planned: + wf_service.trg_validate(uid, 'mrp.procurement', proc.id, 'button_check', cr) + cr.execute('select name,state from mrp_procurement where id=%d', (proc.id,)) + name,state = cr.fetchone() + if state=='exception': + report.append('PROC %d: MTS - %3d %-5s - %s' % (proc.id,proc.product_qty,proc.product_uom.name, proc.product_id.name,)) + report_except +=1 + else: + report_later +=1 + report_total +=1 + cr.commit() + offset += len(ids) + end_date = time.strftime('%Y-%m-%d, %Hh %Mm %Ss') + if 'user_id' in data['form'] and data['form']['user_id']: + request = pooler.get_pool(cr.dbname).get('res.request') + summary = '''Here is the procurement scheduling report. + +Computation Started; %s +Computation Finnished; %s + +Total procurement: %d +Exception procurement: %d +Not run now procurement: %d + +Exceptions; +'''% (start_date,end_date,report_total, report_except,report_later) + summary += '\n'.join(report) + request.create(cr, uid, + {'name' : "Procurement calculation report.", + 'act_from' : data['form']['user_id'], + 'act_to' : data['form']['user_id'], + 'body': summary, + }) + cr.commit() + cr.close() + return {} + +def create_automatic_op(cr, uid, data, context): + product_obj = pooler.get_pool(cr.dbname).get('product.product') + proc_obj = pooler.get_pool(cr.dbname).get('mrp.procurement') + warehouse_obj = pooler.get_pool(cr.dbname).get('stock.warehouse') + wf_service = netsvc.LocalService("workflow") + + cr.execute('select id from stock_warehouse') + warehouses = [x for x, in cr.fetchall()] + cr.execute('select id from product_product') + products_id = [x for x, in cr.fetchall()] + products = dict(zip(products_id, product_obj.browse(cr, uid, products_id, context))) + for warehouse in warehouses: + v_stock = product_obj._product_virtual_available(cr, uid, products_id, "What the fuck", {'warehouse': warehouse}) + cr.execute("select lot_stock_id from stock_warehouse") + location_ids_str = ','.join([str(id) for id, in cr.fetchall()]) + dest_location = warehouse_obj.read(cr, uid, [warehouse], ['lot_input_id'])[0]['lot_input_id'][0] + for prod_id, available in v_stock.items(): + if available >= 0: + continue + cr.execute('select date_planned from stock_move where location_id in ('+location_ids_str+') and location_dest_id not in ('+location_ids_str+') and product_id=%d order by date_planned asc limit 1', (prod_id,)) + newdate, = cr.fetchone() + proc_id = proc_obj.create(cr, uid, { + 'name': 'PROC:Automatic OP for product:%s' % products[prod_id].name, + 'origin': 'SCHEDULER', + 'date_planned': newdate, + 'product_id': prod_id, + 'product_qty': -available, + 'product_uom': products[prod_id].uom_id.id, + 'location_id': dest_location, + 'procure_method': products[prod_id].procure_method, + }) + wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_confirm', cr) + + +def _procure_orderpoint_confirm(self, db_name, uid, data, context): + cr = pooler.get_db(db_name).cursor() + wf_service = netsvc.LocalService("workflow") + offset = 0 + ids = [1] + if data['form']['automatic']: + create_automatic_op(cr, uid, data, context) + while ids: + cr.execute('select id from stock_warehouse_orderpoint where active offset %d limit 100', (offset,)) + ids = map(lambda x: x[0], cr.fetchall()) + for op in pooler.get_pool(cr.dbname).get('stock.warehouse.orderpoint').browse(cr, uid, ids): + #if op.procurement_id and op.procurement_id.purchase_id: + # if (op.procurement_id.purchase_id.state=='confirmed'): + # # + # # TODO: Should write a request with this warning + # # + # continue + # elif op.procurement_id.purchase_id.state=='draft': + # wf_service = netsvc.LocalService("workflow") + # wf_service.trg_validate(uid, 'purchase.order', op.procurement_id.purchase_id.id, 'purchase_cancel', cr) + prods = pooler.get_pool(cr.dbname).get('stock.location')._product_virtual_get(cr, uid, op.warehouse_id.lot_stock_id.id, [op.product_id.id], {'uom': op.product_uom.id})[op.product_id.id] + if prods < op.product_min_qty: + # order the quantity necessary to get to max(min_qty, max_qty) + qty = max(op.product_min_qty, op.product_max_qty)-prods + reste = qty % op.qty_multiple + if reste>0: + qty += op.qty_multiple-reste + newdate = DateTime.now() + DateTime.RelativeDateTime(days=op.product_id.seller_delay) + proc_id = pooler.get_pool(cr.dbname).get('mrp.procurement').create(cr, uid, { + 'name': 'OP:'+str(op.id), + 'date_planned': newdate.strftime('%Y-%m-%d'), + 'product_id': op.product_id.id, + 'product_qty': qty, + 'product_uom': op.product_uom.id, + 'location_id': op.warehouse_id.lot_input_id.id, + 'procure_method': 'make_to_order', + 'origin': op.name + }) + wf_service = netsvc.LocalService("workflow") + wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_confirm', cr) + wf_service.trg_validate(uid, 'mrp.procurement', proc_id, 'button_check', cr) + pooler.get_pool(cr.dbname).get('stock.warehouse.orderpoint').write(cr, uid, [op.id], {'procurement_id':proc_id}) + offset += len(ids) + cr.commit() + cr.close() + return {} + + diff --git a/addons/mrp/wizard/wizard_orderpoint_procurement.py b/addons/mrp/wizard/wizard_orderpoint_procurement.py new file mode 100644 index 00000000000..664c4229d01 --- /dev/null +++ b/addons/mrp/wizard/wizard_orderpoint_procurement.py @@ -0,0 +1,74 @@ +############################################################################## +# +# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. +# +# $Id$ +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +# +# Order Point Method: +# - Order if the virtual stock of today is bellow the min of the defined order point +# + +import wizard +import threading +from schedulers import _procure_orderpoint_confirm + +parameter_form = '''<?xml version="1.0"?> +<form string="Parameters" colspan="4"> + <separator string="Time (days)" colspan="4"/> + <field name="po_lead"/> + <field name="security_lead"/> + <field name="automatic" /> + <separator string="Control" colspan="4"/> + <field name="user_id"/> +</form>''' + +parameter_fields = { + 'po_lead': {'string':'PO Lead Time', 'type':'float', 'required':True, 'default': lambda *a: 1.0}, + 'security_lead': {'string':'Security Days', 'type':'float', 'required':True, 'default': lambda *a: 5.0}, + 'automatic': {'string': 'Automatic orderpoint', 'type': 'boolean', 'help': 'If the stock of a product is under 0, it will act like an orderpoint', 'default': lambda *a: False}, + 'user_id': {'string':'Send Result To', 'type':'many2one', 'relation':'res.users', 'default': lambda uid,data,state: uid}, +} + +def _procure_calculation(self, cr, uid, data, context): + threaded_calculation = threading.Thread(target=_procure_orderpoint_confirm, args=(self, cr.dbname, uid, data, context)) + threaded_calculation.start() + return {} + +class procurement_compute(wizard.interface): + states = { + 'init': { + 'actions': [], + 'result': {'type': 'form', 'arch':parameter_form, 'fields': parameter_fields, 'state':[('end','Cancel'),('compute','Compute Procurements')]} + }, + 'compute': { + 'actions': [_procure_calculation], + 'result': {'type': 'state', 'state':'end'} + }, + } +procurement_compute('mrp.procurement.orderpoint.compute') + + diff --git a/addons/mrp/wizard/wizard_price.py b/addons/mrp/wizard/wizard_price.py new file mode 100644 index 00000000000..44103bc5146 --- /dev/null +++ b/addons/mrp/wizard/wizard_price.py @@ -0,0 +1,54 @@ +# -*- coding: iso-8859-1 -*- +############################################################################## +# +# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. +# Fabien Pinckaers <fp@tiny.Be> +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +import wizard + +price_form = '''<?xml version="1.0"?> +<form string="Paid ?"> + <field name="number"/> +</form>''' + +price_fields = { + 'number': {'string':'Number of products to produce', 'type':'integer', 'required':True}, +} + +class wizard_price(wizard.interface): + states = { + 'init': { + 'actions': [], + 'result': {'type':'form', 'arch':price_form, 'fields':price_fields, 'state':[('end','Cancel'),('price','Print product price') ]} + }, + 'price': { + 'actions': [], + 'result': {'type':'print', 'report':'product.price', 'state':'end'} + } + } +wizard_price('product_price') + + diff --git a/addons/mrp/wizard/wizard_procurement.py b/addons/mrp/wizard/wizard_procurement.py new file mode 100644 index 00000000000..4832c36879a --- /dev/null +++ b/addons/mrp/wizard/wizard_procurement.py @@ -0,0 +1,74 @@ +############################################################################## +# +# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. +# +# $Id$ +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +import wizard +from schedulers import _procure_confirm +import threading + +parameter_form = '''<?xml version="1.0"?> +<form string="Parameters" colspan="4"> + <separator string="Time (days)" colspan="4"/> + <field name="po_lead"/> + <field name="picking_lead"/> + <field name="schedule_cycle"/> + <field name="po_cycle"/> + <field name="security_lead"/> + <separator string="Control" colspan="4"/> + <field name="user_id"/> +</form>''' + +parameter_fields = { + 'schedule_cycle': {'string':'Scheduler Cycle', 'type':'float', 'required':True, 'default': lambda *a: 1.0}, + 'po_cycle': {'string':'PO Cycle', 'type':'float', 'required':True, 'default': lambda *a: 1.0}, + 'po_lead': {'string':'PO Lead Time', 'type':'float', 'required':True, 'default': lambda *a: 1.0}, + 'security_lead': {'string':'Security Days', 'type':'float', 'required':True, 'default': lambda *a: 5.0}, + 'picking_lead': {'string':'Picking Lead Time', 'type':'float', 'required':True, 'default': lambda *a: 1.0}, + 'user_id': {'string':'Send Result To', 'type':'many2one', 'relation':'res.users', 'default': lambda uid,data,state: uid}, +} + +def _procure_calculation(self, cr, uid, data, context): + #CHECKME: I wonder if it would be a good idea to pass the cursor... + # in doubt, I didn't + threaded_calculation = threading.Thread(target=_procure_confirm, args=(self, uid, data, context)) + threaded_calculation.start() + return {} + +class procurement_compute(wizard.interface): + states = { + 'init': { + 'actions': [], + 'result': {'type': 'form', 'arch':parameter_form, 'fields': parameter_fields, 'state':[('end','Cancel'),('compute','Compute Procurements') ]} + }, + 'compute': { + 'actions': [_procure_calculation], + 'result': {'type': 'state', 'state':'end'} + }, + } +procurement_compute('mrp.procurement.compute') + diff --git a/addons/mrp/wizard/wizard_schedulers_all.py b/addons/mrp/wizard/wizard_schedulers_all.py new file mode 100644 index 00000000000..cd0ab566daf --- /dev/null +++ b/addons/mrp/wizard/wizard_schedulers_all.py @@ -0,0 +1,79 @@ +############################################################################## +# +# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. +# +# $Id$ +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +import wizard +from schedulers import _procure_confirm +from schedulers import _procure_orderpoint_confirm +import threading + +parameter_form = '''<?xml version="1.0"?> +<form string="Scheduler Parameters" colspan="4"> + <separator string="Time (days)" colspan="4"/> + <field name="po_lead"/> + <field name="picking_lead"/> + <field name="schedule_cycle"/> + <field name="po_cycle"/> + <field name="security_lead"/> + <field name="automatic" /> + <separator string="Control" colspan="4"/> + <field name="user_id"/> +</form>''' + +parameter_fields = { + 'schedule_cycle': {'string':'Scheduler Cycle', 'type':'float', 'required':True, 'default': lambda *a: 1.0}, + 'po_cycle': {'string':'PO Cycle', 'type':'float', 'required':True, 'default': lambda *a: 1.0}, + 'po_lead': {'string':'PO Lead Time', 'type':'float', 'required':True, 'default': lambda *a: 1.0}, + 'security_lead': {'string':'Security Days', 'type':'float', 'required':True, 'default': lambda *a: 50.0}, + 'picking_lead': {'string':'Picking Lead Time', 'type':'float', 'required':True, 'default': lambda *a: 1.0}, + 'automatic': {'string': 'Automatic orderpoint', 'type': 'boolean', 'help': 'Triggers an automatic procurement for all products that have a virtual stock under 0.', 'default': lambda *a: False}, + 'user_id': {'string':'Send Result To', 'type':'many2one', 'relation':'res.users', 'default': lambda uid,data,state: uid}, +} + +def _procure_calculation_all(self, db_name, uid, data, context): + _procure_confirm(self, db_name, uid, data, context) + _procure_orderpoint_confirm(self, db_name, uid, data, context) + return {} + +def _procure_calculation(self, cr, uid, data, context): + threaded_calculation = threading.Thread(target=_procure_calculation_all, args=(self, cr.dbname, uid, data, context)) + threaded_calculation.start() + return {} + +class procurement_compute(wizard.interface): + states = { + 'init': { + 'actions': [], + 'result': {'type': 'form', 'arch':parameter_form, 'fields': parameter_fields, 'state':[('end','Cancel'),('compute','Compute Procurements') ]} + }, + 'compute': { + 'actions': [_procure_calculation], + 'result': {'type': 'state', 'state':'end'} + }, + } +procurement_compute('mrp.procurement.compute.all') diff --git a/addons/mrp/wizard/wizard_track_prod.py b/addons/mrp/wizard/wizard_track_prod.py new file mode 100644 index 00000000000..ca5b335f5ac --- /dev/null +++ b/addons/mrp/wizard/wizard_track_prod.py @@ -0,0 +1,109 @@ +############################################################################## +# +# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. +# +# $Id$ +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +import wizard +import netsvc +import pooler + +import time +from osv import osv +from tools.misc import UpdateableStr + +arch = UpdateableStr() +fields = {} + +def _get_moves(self, cr, uid, data, context): + prod_obj = pooler.get_pool(cr.dbname).get('mrp.production') + prod = prod_obj.browse(cr, uid, [data['id']])[0] + res = {} + fields.clear() + if prod.state != 'done': + arch.string = '''<?xml version="1.0"?><form string="Track lines"><label colspan="4" string="You can not split an unfinished production output" /></form>''' + res['moves'] = [] + else: + arch_lst = ['<?xml version="1.0"?>', '<form string="Track lines">', '<label colspan="4" string="The field on each line says if this lot should be tracked or not." />'] + for m in [line for line in prod.move_created_ids]: + quantity = m.product_qty + arch_lst.append('<field name="track%s" />\n<newline />' % m.id) + fields['track%s' % m.id] = {'string' : m.product_id.name, 'type' : 'boolean', 'default' : lambda x,y,z: False} + res.setdefault('moves', []).append(m.id) + arch_lst.append('</form>') + arch.string = '\n'.join(arch_lst) + return res + +def _track_lines(self, cr, uid, data, context): + if not data['form']['moves']: + return {} + prodlot_obj = pooler.get_pool(cr.dbname).get('stock.production.lot') + lot_obj = pooler.get_pool(cr.dbname).get('stock.lot') + move_obj = pooler.get_pool(cr.dbname).get('stock.move') + + new_lot = lot_obj.create(cr, uid, {'name': 'PRODUCTION:%d' % data['id']}) + for idx, move in enumerate(move_obj.browse(cr, uid, data['form']['moves'])): + if data['form']['track%s' % move.id]: + for idx in range(move.product_qty): + update_val = {'product_qty': 1, 'lot_id': new_lot} + if idx: + current_move = move_obj.copy(cr, uid, move.id, {'state': move.state, 'production_id': move.production_id.id}) + else: + current_move = move.id + new_prodlot = prodlot_obj.create(cr, uid, {'name': 'PRODUCTION:%d:LOT:%d' % (data['id'], idx+1)}) + update_val['prodlot_id'] = new_prodlot + move_obj.write(cr, uid, [current_move], update_val) + return {} + +class wizard_track_move(wizard.interface): + def _next(self, cr, uid, data, context): + prod_obj = pooler.get_pool(cr.dbname).get('mrp.production') + prod = prod_obj.browse(cr, uid, [data['id']])[0] + if prod.state != 'done': + return 'notrack' + else: + return 'track' + states = { + 'init': { + 'actions': [], + 'result': {'type':'choice', 'next_state': _next} + }, + 'notrack':{ + 'actions':[_get_moves], + 'result':{'type':'form', 'arch':arch, 'fields':fields, 'state':[('end', 'Cancel')]} + }, + 'track':{ + 'actions':[_get_moves], + 'result': {'type':'form', 'arch':arch, 'fields':fields, 'state':[('end','Cancel'),('split','Track')]} + }, + 'split': { + 'actions': [_track_lines], + 'result': {'type':'state', 'state':'end'} + } + } + +wizard_track_move('mrp.production.track') + diff --git a/addons/mrp/wizard/wizard_workcenter_load.py b/addons/mrp/wizard/wizard_workcenter_load.py new file mode 100644 index 00000000000..778be6a7bfc --- /dev/null +++ b/addons/mrp/wizard/wizard_workcenter_load.py @@ -0,0 +1,55 @@ +############################################################################## +# +# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +import wizard + +_time_unit_form = '''<?xml version="1.0"?> +<form string="Select time unit"> + <field name="time_unit"/> + <newline/> + <field name="measure_unit"/> +</form>''' + +_time_unit_fields = { + 'time_unit': {'string':'Type of period', 'type':'selection', 'selection':[('day', 'Day by day'),('week', 'Per week'),('month', 'Per month')], 'required':True}, + 'measure_unit': {'string':'Amount measuring unit', 'type':'selection', 'selection':[('hours', 'Amount in hours'),('cycles', 'Amount in cycles')], 'required':True}, +} + +class wizard_mrp_workcenter(wizard.interface): + states = { + 'init': { + 'actions': [], + 'result': {'type':'form', 'arch':_time_unit_form, 'fields':_time_unit_fields, 'state':[('end','Cancel'),('report','Print') ]}, + }, + 'report': { + 'actions': [], + 'result': {'type':'print', 'report':'mrp.workcenter.load', 'state':'end'}, + }, + } + +wizard_mrp_workcenter('mrp.workcenter.load') + |
