mirror of
https://github.com/OCA/rma.git
synced 2025-02-16 17:11:47 +02:00
Merge pull request #12 from akretion/70_add_prepare_methods
70 add prepare methods
This commit is contained in:
@@ -152,33 +152,104 @@ class claim_make_picking(orm.TransientModel):
|
|||||||
def action_cancel(self, cr, uid, ids, context=None):
|
def action_cancel(self, cr, uid, ids, context=None):
|
||||||
return {'type': 'ir.actions.act_window_close'}
|
return {'type': 'ir.actions.act_window_close'}
|
||||||
|
|
||||||
|
def _prepare_picking_vals(
|
||||||
|
self, cr, uid, claim, p_type, partner_id, wizard, context=None):
|
||||||
|
return {
|
||||||
|
'origin': claim.number,
|
||||||
|
'type': p_type,
|
||||||
|
'move_type': 'one', # direct
|
||||||
|
'state': 'draft',
|
||||||
|
'date': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
|
||||||
|
'partner_id': partner_id,
|
||||||
|
'invoice_state': "none",
|
||||||
|
'company_id': claim.company_id.id,
|
||||||
|
'location_id': wizard.claim_line_source_location.id,
|
||||||
|
'location_dest_id': wizard.claim_line_dest_location.id,
|
||||||
|
'note': 'RMA picking %s' % p_type,
|
||||||
|
'claim_id': claim.id,
|
||||||
|
}
|
||||||
|
|
||||||
|
def _prepare_move_vals(
|
||||||
|
self, cr, uid, wizard_line, partner_id, picking_id, claim, wizard,
|
||||||
|
context=None):
|
||||||
|
return {
|
||||||
|
'name': wizard_line.product_id.name_template,
|
||||||
|
'priority': '0',
|
||||||
|
'date': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
|
||||||
|
'date_expected': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
|
||||||
|
'product_id': wizard_line.product_id.id,
|
||||||
|
'product_qty': wizard_line.product_returned_quantity,
|
||||||
|
'product_uom': wizard_line.product_id.uom_id.id,
|
||||||
|
'partner_id': partner_id,
|
||||||
|
'prodlot_id': wizard_line.prodlot_id.id,
|
||||||
|
'picking_id': picking_id,
|
||||||
|
'state': 'draft',
|
||||||
|
'price_unit': wizard_line.unit_sale_price,
|
||||||
|
'company_id': claim.company_id.id,
|
||||||
|
'location_id': wizard.claim_line_source_location.id,
|
||||||
|
'location_dest_id': wizard.claim_line_dest_location.id,
|
||||||
|
'note': 'RMA move',
|
||||||
|
}
|
||||||
|
|
||||||
|
def _create_move(
|
||||||
|
self, cr, uid, wizard_line, partner_id, picking_id, wizard, claim,
|
||||||
|
context=None):
|
||||||
|
move_obj = self.pool['stock.move']
|
||||||
|
move_vals = self._prepare_move_vals(
|
||||||
|
cr, uid, wizard_line, partner_id, picking_id, claim, wizard,
|
||||||
|
context=context)
|
||||||
|
move_id = move_obj.create(cr, uid, move_vals, context=context)
|
||||||
|
return move_id
|
||||||
|
|
||||||
|
def _prepare_procurement_vals(
|
||||||
|
self, cr, uid, wizard, claim, move_id, wizard_line, context=None):
|
||||||
|
return {
|
||||||
|
'name': wizard_line.product_id.name_template,
|
||||||
|
'origin': claim.number,
|
||||||
|
'date_planned': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
|
||||||
|
'product_id': wizard_line.product_id.id,
|
||||||
|
'product_qty': wizard_line.product_returned_quantity,
|
||||||
|
'product_uom': wizard_line.product_id.uom_id.id,
|
||||||
|
'location_id': wizard.claim_line_source_location.id,
|
||||||
|
'procure_method': wizard_line.product_id.procure_method,
|
||||||
|
'move_id': move_id,
|
||||||
|
'company_id': claim.company_id.id,
|
||||||
|
'note': 'RMA procurement',
|
||||||
|
}
|
||||||
|
|
||||||
|
def _create_procurement(
|
||||||
|
self, cr, uid, wizard, claim, move_id, wizard_line, context=None):
|
||||||
|
proc_obj = self.pool['procurement.order']
|
||||||
|
proc_vals = self._prepare_procurement_vals(
|
||||||
|
cr, uid, wizard, claim, move_id, wizard_line, context=context)
|
||||||
|
proc_id = proc_obj.create(cr, uid, proc_vals, context=context)
|
||||||
|
return proc_id
|
||||||
|
|
||||||
# If "Create" button pressed
|
# If "Create" button pressed
|
||||||
def action_create_picking(self, cr, uid, ids, context=None):
|
def action_create_picking(self, cr, uid, ids, context=None):
|
||||||
picking_obj = self.pool.get('stock.picking')
|
picking_obj = self.pool['stock.picking']
|
||||||
|
line_obj = self.pool['claim.line']
|
||||||
|
claim_obj = self.pool['crm.claim']
|
||||||
if context is None:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
view_obj = self.pool.get('ir.ui.view')
|
view_obj = self.pool['ir.ui.view']
|
||||||
name = 'RMA picking out'
|
name = 'RMA picking out'
|
||||||
if context.get('picking_type') == 'out':
|
if context.get('picking_type') == 'out':
|
||||||
p_type = 'out'
|
p_type = 'out'
|
||||||
write_field = 'move_out_id'
|
write_field = 'move_out_id'
|
||||||
note = 'RMA picking out'
|
|
||||||
else:
|
else:
|
||||||
p_type = 'in'
|
p_type = 'in'
|
||||||
write_field = 'move_in_id'
|
write_field = 'move_in_id'
|
||||||
if context.get('picking_type'):
|
if context.get('picking_type'):
|
||||||
note = 'RMA picking ' + str(context.get('picking_type'))
|
name = 'RMA picking ' + str(context.get('picking_type'))
|
||||||
name = note
|
|
||||||
model = 'stock.picking.' + p_type
|
model = 'stock.picking.' + p_type
|
||||||
view_id = view_obj.search(cr, uid,
|
view_id = view_obj.search(cr, uid,
|
||||||
[('model', '=', model),
|
[('model', '=', model),
|
||||||
('type', '=', 'form'),
|
('type', '=', 'form')],
|
||||||
],
|
|
||||||
context=context)[0]
|
context=context)[0]
|
||||||
wizard = self.browse(cr, uid, ids[0], context=context)
|
wizard = self.browse(cr, uid, ids[0], context=context)
|
||||||
claim = self.pool.get('crm.claim').browse(cr, uid,
|
claim = claim_obj.browse(cr, uid, context['active_id'],
|
||||||
context['active_id'],
|
context=context)
|
||||||
context=context)
|
|
||||||
partner_id = claim.delivery_address_id.id
|
partner_id = claim.delivery_address_id.id
|
||||||
line_ids = [x.id for x in wizard.claim_line_ids]
|
line_ids = [x.id for x in wizard.claim_line_ids]
|
||||||
# In case of product return, we don't allow one picking for various
|
# In case of product return, we don't allow one picking for various
|
||||||
@@ -193,9 +264,7 @@ class claim_make_picking(orm.TransientModel):
|
|||||||
_('A product return cannot be created for various '
|
_('A product return cannot be created for various '
|
||||||
'destination locations, please choose line with a '
|
'destination locations, please choose line with a '
|
||||||
'same destination location.'))
|
'same destination location.'))
|
||||||
self.pool.get('claim.line').auto_set_warranty(cr, uid,
|
line_obj.auto_set_warranty(cr, uid, line_ids, context=context)
|
||||||
line_ids,
|
|
||||||
context=context)
|
|
||||||
common_dest_partner_id = self._get_common_partner_from_line(
|
common_dest_partner_id = self._get_common_partner_from_line(
|
||||||
cr, uid, line_ids, context=context)
|
cr, uid, line_ids, context=context)
|
||||||
if not common_dest_partner_id:
|
if not common_dest_partner_id:
|
||||||
@@ -206,54 +275,34 @@ class claim_make_picking(orm.TransientModel):
|
|||||||
'same address.'))
|
'same address.'))
|
||||||
partner_id = common_dest_partner_id
|
partner_id = common_dest_partner_id
|
||||||
# create picking
|
# create picking
|
||||||
picking_id = picking_obj.create(
|
picking_vals = self._prepare_picking_vals(
|
||||||
cr, uid,
|
cr, uid, claim, p_type, partner_id, wizard, context=context)
|
||||||
{'origin': claim.number,
|
picking_id = picking_obj.create(cr, uid, picking_vals, context=context)
|
||||||
'type': p_type,
|
|
||||||
'move_type': 'one', # direct
|
|
||||||
'state': 'draft',
|
|
||||||
'date': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
|
|
||||||
'partner_id': partner_id,
|
|
||||||
'invoice_state': "none",
|
|
||||||
'company_id': claim.company_id.id,
|
|
||||||
'location_id': wizard.claim_line_source_location.id,
|
|
||||||
'location_dest_id': wizard.claim_line_dest_location.id,
|
|
||||||
'note': note,
|
|
||||||
'claim_id': claim.id,
|
|
||||||
},
|
|
||||||
context=context)
|
|
||||||
# Create picking lines
|
# Create picking lines
|
||||||
fmt = DEFAULT_SERVER_DATETIME_FORMAT
|
proc_ids = []
|
||||||
for wizard_claim_line in wizard.claim_line_ids:
|
for wizard_line in wizard.claim_line_ids:
|
||||||
move_obj = self.pool.get('stock.move')
|
if wizard_line.product_id.type not in ['consu', 'product']:
|
||||||
move_id = move_obj.create(
|
continue
|
||||||
cr, uid,
|
move_id = self._create_move(
|
||||||
{'name': wizard_claim_line.product_id.name_template,
|
cr, uid, wizard_line, partner_id, picking_id, wizard, claim,
|
||||||
'priority': '0',
|
|
||||||
'date': time.strftime(fmt),
|
|
||||||
'date_expected': time.strftime(fmt),
|
|
||||||
'product_id': wizard_claim_line.product_id.id,
|
|
||||||
'product_qty': wizard_claim_line.product_returned_quantity,
|
|
||||||
'product_uom': wizard_claim_line.product_id.uom_id.id,
|
|
||||||
'partner_id': partner_id,
|
|
||||||
'prodlot_id': wizard_claim_line.prodlot_id.id,
|
|
||||||
'picking_id': picking_id,
|
|
||||||
'state': 'draft',
|
|
||||||
'price_unit': wizard_claim_line.unit_sale_price,
|
|
||||||
'company_id': claim.company_id.id,
|
|
||||||
'location_id': wizard.claim_line_source_location.id,
|
|
||||||
'location_dest_id': wizard.claim_line_dest_location.id,
|
|
||||||
'note': note,
|
|
||||||
},
|
|
||||||
context=context)
|
context=context)
|
||||||
self.pool.get('claim.line').write(
|
line_obj.write(
|
||||||
cr, uid, wizard_claim_line.id,
|
cr, uid, wizard_line.id, {write_field: move_id},
|
||||||
{write_field: move_id}, context=context)
|
context=context)
|
||||||
|
if p_type == 'out':
|
||||||
|
proc_id = self._create_procurement(
|
||||||
|
cr, uid, wizard, claim, move_id, wizard_line,
|
||||||
|
context=context)
|
||||||
|
proc_ids.append(proc_id)
|
||||||
wf_service = netsvc.LocalService("workflow")
|
wf_service = netsvc.LocalService("workflow")
|
||||||
if picking_id:
|
if picking_id:
|
||||||
wf_service.trg_validate(uid, 'stock.picking',
|
wf_service.trg_validate(uid, 'stock.picking',
|
||||||
picking_id, 'button_confirm', cr)
|
picking_id, 'button_confirm', cr)
|
||||||
picking_obj.action_assign(cr, uid, [picking_id])
|
picking_obj.action_assign(cr, uid, [picking_id])
|
||||||
|
if proc_ids:
|
||||||
|
for proc_id in proc_ids:
|
||||||
|
wf_service.trg_validate(uid, 'procurement.order',
|
||||||
|
proc_id, 'button_confirm', cr)
|
||||||
domain = ("[('type', '=', '%s'), ('partner_id', '=', %s)]" %
|
domain = ("[('type', '=', '%s'), ('partner_id', '=', %s)]" %
|
||||||
(p_type, partner_id))
|
(p_type, partner_id))
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user