[WIP] Add sequence on procurement rule (and route sequence as a related). Change cancel_cascade into propagate, set default True, and copy from rule onto move

bzr revid: jco@openerp.com-20130725153823-qev7t8axcnqyyzxk
This commit is contained in:
Josse Colpaert 2013-07-25 17:38:23 +02:00
parent c932b34e11
commit 8582e0c64a
4 changed files with 20 additions and 14 deletions

View File

@ -81,7 +81,6 @@ class procurement_order(osv.osv):
'location_id': procurement.rule_id.location_src_id.id,
'location_dest_id': procurement.rule_id.location_id.id,
'move_dest_id': procurement.move_dest_id and procurement.move_dest_id.id or False,
#'cancel_cascade': procurement.rule_id and procurement.rule_id.cancel_cascade or False,
'group_id': procurement.group_id and procurement.group_id.id or False,
'rule_id': procurement.rule_id.id,
}

View File

@ -1000,6 +1000,7 @@ class stock_move(osv.osv):
'remaining_qty': fields.function(_get_remaining_qty, type='float', string='Remaining Quantity', digits_compute=dp.get_precision('Product Unit of Measure'), states={'done': [('readonly', True)]}),
'group_id': fields.many2one('procurement.group', 'Procurement Group'),
'rule_id': fields.many2one('procurement.rule', 'Procurement Rule'),
'propagate': fields.boolean('Propagate cancel and split', help='If checked, when this move is cancelled, cancel the linked move too'),
}
def _check_location(self, cr, uid, ids, context=None):
@ -1107,7 +1108,7 @@ class stock_move(osv.osv):
'location_id': _default_location_source,
'location_dest_id': _default_location_destination,
'partner_id': _default_destination_address,
# 'picking_type_id': lambda self, cr, uid, c: self.pool.get('ir.model.data').get_object_reference(cr, uid, 'stock', 'picking_type_internal')[1],
# 'picking_type_id': TODO: will have to depend on context (e.g. by creating from a link from a column in the kanban view
'state': 'draft',
'priority': '1',
'product_qty': 1.0,
@ -1116,6 +1117,7 @@ class stock_move(osv.osv):
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.move', context=c),
'date_expected': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'procure_method': 'make_to_stock',
'propagate': True,
}
def _create_procurement(self, cr, uid, move, context=None):
@ -1125,7 +1127,7 @@ class stock_move(osv.osv):
proc_obj = self.pool.get("procurement.order")
origin = _('Procurement from created by rule %s') % (move.group_id and move.group_id.name or "", move.rule_id and move.rule_id.name or "")
return proc_obj.create(cr, uid, {
'name': _('MTO procurement from rule %s') % move.rule_id and move.rule_id.name or "",
'name': _('MTO from rule %s') % move.rule_id and move.rule_id.name or "",
'origin': origin,
'company_id': move.company_id and move.company_id.id or False,
'date_planned': move.date,
@ -1440,7 +1442,7 @@ class stock_move(osv.osv):
for move in self.browse(cr, uid, ids, context=context):
# FP Note: should we create a MTS procurement here?
if move.move_dest_id:
if move.cancel_cascade:
if move.propagate:
self.action_cancel(cr, uid, [move.move_dest_id.id], context=context)
elif move.move_dest_id.state == 'waiting':
self.write(cr, uid, [move.move_dest_id.id], {'state': 'confirmed'})

View File

@ -63,7 +63,6 @@ class stock_location_path(osv.osv):
("2binvoiced", "To Be Invoiced"),
("none", "Not Applicable")], "Invoice Status",
required=True,),
# 'picking_type': fields.selection([('out','Sending Goods'),('in','Getting Goods'),('internal','Internal')], 'Shipping Type', required=True, select=True, help="Depending on the company, choose whatever you want to receive or send products"),
'picking_type_id': fields.many2one('stock.picking.type', 'Picking Type', help="This is the picking type associated with the different pickings"),
'auto': fields.selection(
[('auto','Automatic Move'), ('manual','Manual Operation'),('transparent','Automatic No Step Added')],
@ -73,13 +72,15 @@ class stock_location_path(osv.osv):
"The 'Automatic Move' value will create a stock move after the current one that will be "\
"validated automatically. With 'Manual Operation', the stock move has to be validated "\
"by a worker. With 'Automatic No Step Added', the location is replaced in the original move."
),
),
'propagate': fields.boolean('Propagate cancel and split', help='If checked, when the previous move is cancelled or split, the move generated by this move will too'),
}
_defaults = {
'auto': 'auto',
'delay': 1,
'invoice_state': 'none',
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'procurement.order', context=c)
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'procurement.order', context=c),
'propagate': True,
}
def _apply(self, cr, uid, rule, move, context=None):
move_obj = self.pool.get('stock.move')
@ -104,6 +105,7 @@ class stock_location_path(osv.osv):
'picking_id': False,
'type': move_obj.get_type_from_usage(cr, uid, move.location_id, move.location_dest_id, context=context),
'rule_id': rule.id,
'propagate': rule.propagate,
})
move_obj.write(cr, uid, [move.id], {
'move_dest_id': move_id,
@ -133,11 +135,14 @@ class procurement_rule(osv.osv):
("2binvoiced", "To Be Invoiced"),
("none", "Not Applicable")], "Invoice Status",
required=True,),
'sequence': fields.related('route_id', 'sequence', string='Route Sequence', store={'stock.location.route': (_get_rules, ['sequence'], 10)}),
'route_sequence': fields.related('route_id', 'sequence', string='Route Sequence', store={'stock.location.route': (_get_rules, ['sequence'], 10)}),
'sequence': fields.integer('Sequence'),
'propagate': fields.boolean('Propagate cancel and split', help='If checked, when the previous move of the move (which was generated by a next procurement) is cancelled or split, the move generated by this move will too'),
}
_defaults = {
'procure_method': 'make_to_stock',
'invoice_state': 'none',
'propagate': True,
}
@ -161,7 +166,8 @@ class procurement_order(osv.osv):
d.update({
'date': newdate,
'procure_method': procure_method,
'route_ids': [(4,x.id) for x in procurement.route_ids]
'route_ids': [(4,x.id) for x in procurement.route_ids],
'propagate': procurement.rule_id.propagate,
})
return d
@ -175,10 +181,10 @@ class procurement_order(osv.osv):
def _search_suitable_rule(self, cr, uid, procurement, domain, context=None):
'''we try to first find a rule among the ones defined on the procurement order group and if none is found, we try on the routes defined for the product, and finally we fallback on the default behavior'''
route_ids = [x.id for x in procurement.route_ids]
res = self.pool.get('procurement.rule').search(cr, uid, domain + [('route_id', 'in', route_ids)], order = 'sequence', context=context)
res = self.pool.get('procurement.rule').search(cr, uid, domain + [('route_id', 'in', route_ids)], order = 'route_sequence, sequence', context=context)
if not res:
route_ids = [x.id for x in procurement.product_id.route_ids]
res = self.pool.get('procurement.rule').search(cr, uid, domain + [('route_id', 'in', route_ids)], order = 'sequence', context=context)
res = self.pool.get('procurement.rule').search(cr, uid, domain + [('route_id', 'in', route_ids)], order = 'route_sequence, sequence', context=context)
if not res:
res = self.pool.get('procurement.rule').search(cr, uid, domain, order='sequence', context=context)
return res
@ -247,7 +253,6 @@ class stock_quant(osv.osv):
class stock_move(osv.osv):
_inherit = 'stock.move'
_columns = {
'cancel_cascade': fields.boolean('Cancel Cascade', help='If checked, when this move is cancelled, cancel the linked move too'),
'putaway_ids': fields.one2many('stock.move.putaway', 'move_id', 'Put Away Suggestions'),
'route_ids': fields.many2many('stock.location.route', 'stock_location_route_move', 'move_id', 'route_id', 'Destination route', help="Preferred route to be followed by the procurement order"),
}

View File

@ -41,7 +41,7 @@
<field name="invoice_state">none</field>
<field name="company_id" ref="stock.res_company_1"/>
<field name="type_proc">move</field>
<field eval="0" name="cancel_cascade"/>
<field eval="0" name="propagate"/>
<field name="procure_method">make_to_order</field>
<field name="picking_type_id" ref="stock.picking_type_in"/>
<field name="name">Receive from Warehouse</field>
@ -55,7 +55,7 @@
<field name="type_proc">move</field>
<field name="invoice_state">none</field>
<field name="company_id" ref="base.main_company"/>
<field eval="0" name="cancel_cascade"/>
<field eval="0" name="propagate"/>
<field name="procure_method">make_to_stock</field>
<field name="picking_type_id" ref="stock.picking_type_out"/>
<field name="name">Deliver Shop</field>