[ADD] production without internal picking

This commit is contained in:
Àngel Àlvarez 2012-04-25 17:58:10 +02:00
commit 5b72519292
5 changed files with 284 additions and 0 deletions

32
__init__.py Normal file
View File

@ -0,0 +1,32 @@
##############################################################################
#
# Copyright (c) 2012 NaN Projectes de Programari Lliure, S.L.
# All Rights Reserved.
# http://www.NaN-tic.com
#
# 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 Affero 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 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import mrp
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

53
__openerp__.py Normal file
View File

@ -0,0 +1,53 @@
##############################################################################
#
# Copyright (c) 2012 NaN Projectes de Programari Lliure, S.L.
# All Rights Reserved.
# http://www.NaN-tic.com
#
# 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 Affero 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 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
{
"name" : "MRP Without internal Picking",
"version" : "0.1",
"author" : "NaN Projectes de Programari Lliure S.L.",
"category" : "Generic Modules/Production",
"website": "http://www.nan-tic.com",
"description": """
""",
"depends" : [
"mrp"
],
"init_xml" : [],
"update_xml" : [
"workflow.xml",
"mrp_view.xml",
],
"demo_xml" : [],
"test": [
],
"active": False,
"installable": True,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

147
mrp.py Normal file
View File

@ -0,0 +1,147 @@
##############################################################################
#
# Copyright (c) 2012 NaN Projectes de Programari Lliure, S.L.
# All Rights Reserved.
# http://www.NaN-tic.com
#
# 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 Affero 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 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from osv import osv, fields
import netsvc
from tools.translate import _
from datetime import datetime
class mrp_production(osv.osv):
_inherit = 'mrp.production'
def action_confirm(self, cr, uid, ids):
proc_ids = []
seq_obj = self.pool.get('ir.sequence')
move_obj = self.pool.get('stock.move')
proc_obj = self.pool.get('procurement.order')
wf_service = netsvc.LocalService("workflow")
for production in self.browse(cr, uid, ids):
if not production.product_lines:
self.action_compute(cr, uid, [production.id])
production = self.browse(cr, uid, [production.id])[0]
routing_loc = None
if production.bom_id.routing_id and production.bom_id.routing_id.location_id:
routing_loc = production.bom_id.routing_id.location_id
routing_loc = routing_loc.id
source = production.product_id.product_tmpl_id.property_stock_production.id
data = {
'name':'PROD:' + production.name,
'date': production.date_planned,
'product_id': production.product_id.id,
'product_qty': production.product_qty,
'product_uom': production.product_uom.id,
'product_uos_qty': production.product_uos and production.product_uos_qty or False,
'product_uos': production.product_uos and production.product_uos.id or False,
'location_id': source,
'location_dest_id': production.location_dest_id.id,
'move_dest_id': production.move_prod_id.id,
'state': 'waiting',
'company_id': production.company_id.id,
}
res_final_id = move_obj.create(cr, uid, data)
self.write(cr, uid, [production.id], {'move_created_ids': [(6, 0, [res_final_id])]})
moves = []
for line in production.product_lines:
move_id = False
newdate = production.date_planned
if line.product_id.type in ('product', 'consu'):
res_dest_id = move_obj.create(cr, uid, {
'name':'PROD:' + production.name,
'date': production.date_planned,
'product_id': line.product_id.id,
'product_qty': line.product_qty,
'product_uom': line.product_uom.id,
'product_uos_qty': line.product_uos and line.product_uos_qty or False,
'product_uos': line.product_uos and line.product_uos.id or False,
'location_id': routing_loc or production.location_src_id.id,
'location_dest_id': source,
'move_dest_id': res_final_id,
'state': 'waiting',
'company_id': production.company_id.id,
})
moves.append(res_dest_id)
proc_vals = self._calc_procurement_vals_from_product_line(cr,
uid, line, res_dest_id)
proc_id = proc_obj.create(cr, uid, proc_vals)
wf_service.trg_validate(uid, 'procurement.order', proc_id, 'button_confirm', cr)
proc_ids.append(proc_id)
self.write(cr, uid, [production.id], {'move_lines': [(6,0,moves)], 'state':'confirmed'})
message = _("Manufacturing order '%s' is scheduled for the %s.") % (
production.name,
datetime.strptime(production.date_planned,'%Y-%m-%d %H:%M:%S').strftime('%m/%d/%Y'),
)
self.log(cr, uid, production.id, message)
# self.action_ready(cr, uid, ids)
return True
def check_availability(self, cr, uid, ids, context=None):
for prod in self.browse(cr, uid, ids ):
for move in prod.move_lines:
print "move state", move.state
if move.state != 'assigned':
return False
return True
def check_production(self, cr, uid, ids, context=None):
wf_service = netsvc.LocalService("workflow")
for prod in self.browse(cr, uid, ids ):
for move in prod.move_lines:
for procurement in move.procurements:
wf_service.trg_validate(uid, 'procurement.order',
procurement.id, 'button_check', cr)
self.check_availability(cr, uid, ids, context)
if self.check_availability(cr, uid, ids, context):
self.action_ready(cr, uid, ids)
return True
def force_production(self, cr, uid, ids, *args):
""" Assigns products.
@param *args: Arguments
@return: True
"""
move_ids=[]
for prod in self.browse(cr, uid, ids ):
move_ids += [x.id for x in prod.move_lines if x.state in ['confirmed','waiting']]
self.pool.get('stock.move').force_assign(cr, uid, move_ids)
# self.action_ready(cr, uid, ids)
return True
mrp_production()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

18
mrp_view.xml Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="mrp_production_form_check_view" model="ir.ui.view">
<field name="name">mrp.production.check.form</field>
<field name="model">mrp.production</field>
<field name="type">form</field>
<field name="inherit_id" ref="mrp.mrp_production_form_view" />
<field name="arch" type="xml">
<button name="button_recreate" states="picking_except" string="Recreate Picking" icon="terp-document-new" position="replace">
<button name="check_production" states="confirmed,picking_except" string="Check Availability" type="object" icon="gtk-jump-to"/>
</button>
</field>
</record>
</data>
</openerp>

34
workflow.xml Normal file
View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="mrp.prod_act_picking" model="workflow.activity">
<field name="wkf_id" ref="mrp.wkf_prod"/>
<field name="name">picking</field>
<field name="kind">function</field>
<field name="action">action_confirm()</field>
</record>
<!-- <record id="mrp.prod_trans_draft_picking" model="workflow.transition">
<field name="act_from" ref="mrp.prod_act_draft"/>
<field name="act_to" ref="mrp.prod_act_ready"/>
<field name="signal">button_confirm</field>
<field name="condition">action_confirm()</field>
</record>
-->
<record id="mrp.prod_trans_draft_picking" model="workflow.transition">
<field name="act_from" ref="mrp.prod_act_draft"/>
<field name="act_to" ref="mrp.prod_act_picking"/>
<field name="signal">button_confirm</field>
<field name="condition">test_if_product()</field>
</record>
<record id="mrp.prod_trans_picking_ready" model="workflow.transition">
<field name="act_from" ref="mrp.prod_act_picking"/>
<field name="act_to" ref="mrp.prod_act_ready"/>
<field name="signal"></field>
<field name="condition">check_availability()</field>
</record>
</data>
</openerp>