[WIP] Implement procurement rule for manufacturing (similar to purchase)

bzr revid: jco@openerp.com-20130711170604-yxm1d7a0qmdpps60
This commit is contained in:
Josse Colpaert 2013-07-11 19:06:04 +02:00
parent 756e40e29a
commit a0f7808075
3 changed files with 64 additions and 38 deletions

View File

@ -929,36 +929,36 @@ class mrp_production(osv.osv):
'company_id': production.company_id.id,
})
def _make_production_internal_shipment(self, cr, uid, production, context=None):
ir_sequence = self.pool.get('ir.sequence')
stock_picking = self.pool.get('stock.picking')
routing_loc = None
pick_type = 'internal'
partner_id = False
# Take routing address as a Shipment Address.
# If usage of routing location is a internal, make outgoing shipment otherwise internal shipment
if production.bom_id.routing_id and production.bom_id.routing_id.location_id:
routing_loc = production.bom_id.routing_id.location_id
if routing_loc.usage != 'internal':
pick_type = 'out'
partner_id = routing_loc.partner_id and routing_loc.partner_id.id or False
# Take next Sequence number of shipment base on type
pick_name = ir_sequence.get(cr, uid, 'stock.picking.' + pick_type)
picking_id = stock_picking.create(cr, uid, {
'name': pick_name,
'origin': (production.origin or '').split(':')[0] + ':' + production.name,
'type': pick_type,
'move_type': 'one',
'state': 'auto',
'partner_id': partner_id,
'auto_picking': self._get_auto_picking(cr, uid, production),
'company_id': production.company_id.id,
})
production.write({'picking_id': picking_id}, context=context)
return picking_id
# def _make_production_internal_shipment(self, cr, uid, production, context=None):
# ir_sequence = self.pool.get('ir.sequence')
# stock_picking = self.pool.get('stock.picking')
# routing_loc = None
# pick_type = 'internal'
# partner_id = False
#
# # Take routing address as a Shipment Address.
# # If usage of routing location is a internal, make outgoing shipment otherwise internal shipment
# if production.bom_id.routing_id and production.bom_id.routing_id.location_id:
# routing_loc = production.bom_id.routing_id.location_id
# if routing_loc.usage != 'internal':
# pick_type = 'out'
# partner_id = routing_loc.partner_id and routing_loc.partner_id.id or False
#
# # Take next Sequence number of shipment base on type
# pick_name = ir_sequence.get(cr, uid, 'stock.picking.' + pick_type)
#
# picking_id = stock_picking.create(cr, uid, {
# 'name': pick_name,
# 'origin': (production.origin or '').split(':')[0] + ':' + production.name,
# 'type': pick_type,
# 'move_type': 'one',
# 'state': 'auto',
# 'partner_id': partner_id,
# 'auto_picking': self._get_auto_picking(cr, uid, production),
# 'company_id': production.company_id.id,
# })
# production.write({'picking_id': picking_id}, context=context)
# return picking_id
def _make_production_produce_line(self, cr, uid, production, context=None):
stock_move = self.pool.get('stock.move')
@ -1018,7 +1018,7 @@ class mrp_production(osv.osv):
uncompute_ids = filter(lambda x:x, [not x.product_lines and x.id or False for x in self.browse(cr, uid, ids, context=context)])
self.action_compute(cr, uid, uncompute_ids, context=context)
for production in self.browse(cr, uid, ids, context=context):
shipment_id = self._make_production_internal_shipment(cr, uid, production, context=context)
#shipment_id = self._make_production_internal_shipment(cr, uid, production, context=context)
produce_move_id = self._make_production_produce_line(cr, uid, production, context=context)
# Take routing location as a Source Location.
@ -1031,8 +1031,6 @@ class mrp_production(osv.osv):
shipment_move_id = self._make_production_internal_shipment_line(cr, uid, line, shipment_id, consume_move_id,\
destination_location_id=source_location_id, context=context)
self._make_production_line_procurement(cr, uid, line, shipment_move_id, context=context)
self.pool.get('stock.picking').signal_button_confirm(cr, uid, [shipment_id])
production.write({'state':'confirmed'}, context=context)
return shipment_id

View File

@ -962,11 +962,8 @@
<attribute name="invisible">False</attribute>
</xpath>
<group name="procurement_help" position="inside">
<p attrs="{'invisible': ['|','|',('type','=','service'),('procure_method','&lt;&gt;','make_to_order'),('supply_method','&lt;&gt;','produce')]}">
When you sell this product, OpenERP will trigger <b>a manufacturing
order</b> using the bill of materials assigned to this product.
The delivery order will be ready once the production is done.
</p>
<!-- TODO: create help with routes -->
<p>Here should come some help about manufacturing routes</p>
</group>
</field>
</record>

View File

@ -25,6 +25,13 @@ from openerp.osv import fields
from openerp.osv import osv
from openerp.tools.translate import _
class procurement_rule(osv.osv):
_inherit = 'procurement.rule'
def _get_action(self, cr, uid, context=None):
return [('manufacture', 'Manufacture')] + super(procurement_rule, self)._get_action(cr, uid, context=context)
class procurement_order(osv.osv):
_inherit = 'procurement.order'
_columns = {
@ -33,6 +40,30 @@ class procurement_order(osv.osv):
'production_id': fields.many2one('mrp.production', 'Manufacturing Order'),
}
def _find_suitable_rule(self, cr, uid, procurement, context=None):
rule_id = super(procurement_order, self)._find_suitable_rule(cr, uid, procurement, context=context)
if not rule_id:
#if there isn't any specific procurement.rule defined for the product, we try to directly supply it from a supplier
if procurement.product_id.supply_method == 'manufacture' and procurement.product_id.bom_id: #Actually not needed anymore?
rule_id = self.pool.get('procurement.rule').search(cr, uid, [('action', '=', 'manufacture'), ('location_id', '=', procurement.location_id.id)], context=context)
rule_id = rule_id and rule_id[0] or False
return rule_id
def _run(self, cr, uid, procurement, context=None):
if procurement.rule_id and procurement.rule_id.action == 'manufacture':
#make a manufacturing order for the procurement
return self.make_mo(cr, uid, [procurement.id], context=context)
return super(procurement_order, self)._run(cr, uid, procurement, context=context)
def _check(self, cr, uid, procurement, context=None):
if procurement.production_id and procurement.production_id.state == 'done': # TOCHECK: no better method?
return True
return super(procurement_order, self)._check(cr, uid, procurement, context=context)
def _prepare_order_line_procurement(self, cr, uid, order, line, move_id, date_planned, context=None):
result = super(procurement_order, self)._prepare_order_line_procurement(cr, uid, order, line, move_id, date_planned, context)
result['property_ids'] = [(6, 0, [x.id for x in line.property_ids])]