[IMP] add internal picking after new picking in

This commit is contained in:
Benoit Guillot
2012-09-17 16:54:41 +02:00
parent 9cc576fd66
commit c7fec0b53d
10 changed files with 246 additions and 4 deletions

View File

@@ -45,6 +45,7 @@ THIS MODULE REPLACES Akretion stock_rma from V6.0
'init_xml': ['rma_data.xml',],
'update_xml': [
'wizard/claim_make_picking_view.xml',
'wizard/claim_make_picking_from_picking_view.xml',
'wizard/returned_lines_from_serial_wizard_view.xml',
# 'wizard/returned_lines_from_invoice_wizard_view.xml',
# 'wizard/picking_from_returned_lines_wizard_view.xml',

View File

@@ -100,7 +100,8 @@ class claim_line(osv.osv):
'last_state_change': fields.date('Last change', help="To set the last state / substate change"),
'invoice_line_id': fields.many2one('account.invoice.line', 'Invoice Line', help='The invoice line related to the returned product'),
'refund_line_id': fields.many2one('account.invoice.line', 'Refund Line', help='The refund line related to the returned product'),
'move_line_id': fields.many2one('stock.move', 'Move Line', help='The move line related to the returned product'),
'move_in_id': fields.many2one('stock.move', 'Move Line from picking in', help='The move line related to the returned product'),
'move_out_id': fields.many2one('stock.move', 'Move Line from picking out', help='The move line related to the returned product'),
}
_defaults = {

View File

@@ -30,6 +30,7 @@ class stock_picking(osv.osv):
_columns = {
'claim_id': fields.many2one('crm.claim', 'Claim'),
'claim_picking': fields.boolean('Picking from Claim'),
}
class stock_warehouse(osv.osv):
@@ -41,4 +42,5 @@ class stock_warehouse(osv.osv):
'lot_rma_id': fields.many2one('stock.location', 'Location RMA'),
'lot_carrier_loss_id': fields.many2one('stock.location', 'Location Carrier Loss'),
'lot_breakage_loss_id': fields.many2one('stock.location', 'Location Breakage Loss'),
'lot_refurbish_id': fields.many2one('stock.location', 'Location Refurbish'),
}

View File

@@ -19,6 +19,11 @@
<field name="usage">internal</field>
<field name="location_id" ref="stock.stock_location_company"/>
</record>
<record id="stock_location_refurbish" model="stock.location">
<field name="name">Refurbish</field>
<field name="usage">internal</field>
<field name="location_id" ref="stock.stock_location_company"/>
</record>
<!--
Default Values for : Stock Warehouse
-->
@@ -26,6 +31,7 @@
<field name="lot_rma_id" ref="stock_location_rma"/>
<field name="lot_breakage_loss_id" ref="stock_location_breakage_loss"/>
<field name="lot_carrier_loss_id" ref="stock_location_carrier_loss"/>
<field name="lot_refurbish_id" ref="stock_location_refurbish"/>
</record>
</data>
</openerp>

View File

@@ -19,6 +19,21 @@
<data>
<xpath expr="/form/notebook/page[@string='Additional Info']/field[@name='type']" position="after">
<field name="claim_id" />
<field name="claim_picking" invisible="1"/>
</xpath>
<xpath expr="/form/notebook/page[@string='General Information']/group/button[@string='Return Products']" position="before">
<button name="%(action_stock_picking_from_claim_picking)d"
string="Product to stock" type="action"
attrs="{'invisible':['|',('state','&lt;&gt;','done'),
('claim_picking', '=', False)]}"/>
<button name="%(action_loss_picking_from_claim_picking)d"
string="Product to Loss" type="action"
attrs="{'invisible':['|',('state','&lt;&gt;','done'),
('claim_picking', '=', False)]}"/>
<button name="%(action_used_picking_from_claim_picking)d"
string="Product to refurbish stock" type="action"
attrs="{'invisible':['|',('state','&lt;&gt;','done'),
('claim_picking', '=', False)]}"/>
</xpath>
</data>
</field>
@@ -51,6 +66,7 @@
<field name="lot_rma_id"/>
<field name="lot_carrier_loss_id"/>
<field name="lot_breakage_loss_id"/>
<field name="lot_refurbish_id"/>
</xpath>
</data>
</field>

View File

@@ -31,3 +31,4 @@ import get_empty_serial
import claim_make_picking
import account_invoice_refund
import claim_make_picking_from_picking

View File

@@ -41,8 +41,9 @@ class claim_make_picking(osv.osv_memory):
# Get default source location
def _get_source_loc(self, cr, uid, context):
if context is None: context = {}
warehouse_obj = self.pool.get('stock.warehouse')
warehouse_id = context['warehouse_id']
warehouse_id = context.get('warehouse_id')
if context.get('picking_type') == 'out':
loc_id = warehouse_obj.read(cr, uid, warehouse_id, ['lot_stock_id'], context=context)['lot_stock_id'][0]
elif context.get('picking_type') in ['in', 'loss'] and context.get('partner_id'):
@@ -53,8 +54,9 @@ class claim_make_picking(osv.osv_memory):
# Get default destination location
def _get_dest_loc(self, cr, uid, context):
if context is None: context = {}
warehouse_obj = self.pool.get('stock.warehouse')
warehouse_id = context['warehouse_id']
warehouse_id = context.get('warehouse_id')
if context.get('picking_type') == 'out':
loc_id = self.pool.get('res.partner').read(cr, uid, context.get('partner_id'), ['property_stock_customer'], context=context)['property_stock_customer'][0]
elif context.get('picking_type') == 'in':
@@ -81,6 +83,7 @@ class claim_make_picking(osv.osv_memory):
p_type = 'in'
view_xml_id = 'view_picking_in_form'
view_name = 'stock.picking.in.form'
write_field = 'move_in_id'
if context.get('picking_type') == 'in':
note = 'RMA picking in'
name = 'Customer picking in'
@@ -89,6 +92,7 @@ class claim_make_picking(osv.osv_memory):
note = 'RMA product loss'
elif context.get('picking_type') == 'out':
p_type = 'out'
write_field = 'move_out_id'
note = 'RMA picking out'
name = 'Customer picking out'
view_xml_id = 'view_picking_in_form'
@@ -116,6 +120,7 @@ class claim_make_picking(osv.osv_memory):
'location_dest_id': wizard.claim_line_dest_location.id,
'note' : note,
'claim_id': claim.id,
'claim_picking': True
})
# Create picking lines
for wizard_claim_line in wizard.claim_line_ids:
@@ -140,6 +145,7 @@ class claim_make_picking(osv.osv_memory):
'location_dest_id': wizard.claim_line_dest_location.id,
'note': note,
})
self.pool.get('claim.line').write(cr, uid, wizard_claim_line.id, {write_field: move_id}, context=context)
wf_service = netsvc.LocalService("workflow")
if picking_id:
wf_service.trg_validate(uid, 'stock.picking', picking_id,'button_confirm', cr)

View File

@@ -0,0 +1,144 @@
# -*- coding: utf-8 -*-
#########################################################################
# #
# #
#########################################################################
# #
# crm_claim_rma for OpenERP #
# Copyright (C) 2009-2012 Akretion, Emmanuel Samyn, #
# Benoît GUILLOT <benoit.guillot@akretion.com> #
#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 3 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, see <http://www.gnu.org/licenses/>. #
#########################################################################
from osv import fields, osv
import time
from tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
import netsvc
class claim_make_picking_from_picking(osv.osv_memory):
_name='claim_make_picking_from_picking.wizard'
_description='Wizard to create pickings from picking lines'
_columns = {
'picking_line_source_location' : fields.many2one('stock.location', 'Source Location',help="Location where the returned products are from.", required=True),
'picking_line_dest_location' : fields.many2one('stock.location', 'Dest. Location',help="Location where the system will stock the returned products.", required=True),
'picking_line_ids' : fields.many2many('stock.move', 'claim_picking_line_picking', 'claim_picking_id', 'picking_line_id', 'Picking lines'),
}
def _get_picking_lines(self, cr, uid, context):
return self.pool.get('stock.picking').read(cr, uid, context['active_id'], ['move_lines'], context=context)['move_lines']
# Get default source location
def _get_source_loc(self, cr, uid, context):
if context is None: context = {}
warehouse_obj = self.pool.get('stock.warehouse')
warehouse_id = context.get('warehouse_id')
return warehouse_obj.read(cr, uid, warehouse_id, ['lot_rma_id'], context=context)['lot_rma_id'][0]
# Get default destination location
def _get_dest_loc(self, cr, uid, context):
if context is None: context = {}
warehouse_obj = self.pool.get('stock.warehouse')
warehouse_id = context.get('warehouse_id')
if context.get('picking_type'):
context_loc = context.get('picking_type')[8:]
loc_field = 'lot_%s_id' %context.get('picking_type')[8:]
loc_id = warehouse_obj.read(cr, uid, warehouse_id, [loc_field], context=context)[loc_field][0]
return loc_id
_defaults = {
'picking_line_source_location': _get_source_loc,
'picking_line_dest_location': _get_dest_loc,
'picking_line_ids': _get_picking_lines,
}
def action_cancel(self,cr,uid,ids,conect=None):
return {'type': 'ir.actions.act_window_close',}
# If "Create" button pressed
def action_create_picking_from_picking(self, cr, uid, ids, context=None):
picking_obj = self.pool.get('stock.picking')
move_obj = self.pool.get('stock.move')
view_obj = self.pool.get('ir.ui.view')
if context is None: context = {}
p_type = 'internal'
if context.get('picking_type'):
context_type = context.get('picking_type')[8:]
note = 'Internal picking from RMA to %s' %context_type
name = 'Internal picking to %s' %context_type
view_id = view_obj.search(cr, uid, [
('xml_id', '=', 'view_picking_form'),
('model', '=', 'stock.picking'),
('type', '=', 'form'),
('name', '=', 'stock.picking.form')
], context=context)[0]
wizard = self.browse(cr, uid, ids[0], context=context)
prev_picking = picking_obj.browse(cr, uid, context['active_id'], context=context)
partner_id = prev_picking.partner_id.id
# create picking
picking_id = picking_obj.create(cr, uid, {
'origin': prev_picking.origin,
'type': p_type,
'move_type': 'one', # direct
'state': 'draft',
'date': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
'address_id': prev_picking.address_id.id,
'invoice_state': "none",
'company_id': prev_picking.company_id.id,
'location_id': wizard.picking_line_source_location.id,
'location_dest_id': wizard.picking_line_dest_location.id,
'note' : note,
'claim_id': prev_picking.claim_id.id,
'claim_picking': True
})
# Create picking lines
for wizard_picking_line in wizard.picking_line_ids:
move_id = move_obj.create(cr, uid, {
'name' : wizard_picking_line.product_id.name_template, # Motif : crm id ? stock_picking_id ?
'priority': '0',
#'create_date':
'date': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
'date_expected': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
'product_id': wizard_picking_line.product_id.id,
'product_qty': wizard_picking_line.product_qty,
'product_uom': wizard_picking_line.product_uom.id,
'address_id': prev_picking.address_id.id,
'prodlot_id': wizard_picking_line.prodlot_id.id,
# 'tracking_id':
'picking_id': picking_id,
'state': 'draft',
'price_unit': wizard_picking_line.price_unit,
# 'price_currency_id': claim_id.company_id.currency_id.id, # from invoice ???
'company_id': prev_picking.company_id.id,
'location_id': wizard.picking_line_source_location.id,
'location_dest_id': wizard.picking_line_dest_location.id,
'note': note,
})
wizard_move = move_obj.write(cr, uid, wizard_picking_line.id, {'move_dest_id': move_id}, context=context)
wf_service = netsvc.LocalService("workflow")
if picking_id:
wf_service.trg_validate(uid, 'stock.picking', picking_id,'button_confirm', cr)
picking_obj.action_assign(cr, uid, [picking_id])
return {
'name': '%s' % name,
'view_type': 'form',
'view_mode': 'form',
'view_id': view_id,
'domain' : "[('type', '=', '%s'),('partner_id','=',%s)]" % (p_type, partner_id),
'res_model': 'stock.picking',
'res_id': picking_id,
'type': 'ir.actions.act_window',
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
crm_claim_rma for OpenERP
Copyright (C) 2011 Akretion Benoît GUILLOT <benoit.guillot@akretion.com>
The licence is in the file __openerp__.py
-->
<openerp>
<data>
<record id="view_claim_picking_from_picking" model="ir.ui.view">
<field name="name">claim_picking</field>
<field name="model">claim_make_picking_from_picking.wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Select lines to add in picking">
<separator string="Locations" colspan="4"/>
<field name="picking_line_source_location" nolabel="1" />
<field name="picking_line_dest_location" nolabel="1" />
<separator string="Select lines for picking" colspan="4"/>
<field name="picking_line_ids" nolabel="1" colspan="4"/>
<group col="4" colspan="2">
<button special="cancel" string="Cancel" name="action_cancel" type="object" icon='gtk-cancel'/>
<button name="action_create_picking_from_picking" string="Create picking"
icon='gtk-ok' type="object"/>
</group>
</form>
</field>
</record>
<record id="action_stock_picking_from_claim_picking" model="ir.actions.act_window">
<field name="name">action_stock_picking_from_claim_picking</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">claim_make_picking_from_picking.wizard</field>
<field name="src_model">stock.picking</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="context">{'picking_type': 'picking_stock'}</field>
</record>
<record id="action_loss_picking_from_claim_picking" model="ir.actions.act_window">
<field name="name">action_loss_picking_from_claim_picking</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">claim_make_picking_from_picking.wizard</field>
<field name="src_model">stock.picking</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="context">{'picking_type': 'picking_breakage_loss'}</field>
</record>
<record id="action_used_picking_from_claim_picking" model="ir.actions.act_window">
<field name="name">action_used_picking_from_claim_picking</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">claim_make_picking_from_picking.wizard</field>
<field name="src_model">stock.picking</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="context">{'picking_type': 'picking_refurbish'}</field>
</record>
</data>
</openerp>

View File

@@ -20,7 +20,8 @@
<field name="claim_line_ids" nolabel="1" colspan="4"/>
<group col="4" colspan="2">
<button special="cancel" string="Cancel" name="action_cancel" type="object" icon='gtk-cancel'/>
<button name="action_create_picking" string="Create picking" icon='gtk-ok' type="object"/>
<button name="action_create_picking" string="Create picking"
icon='gtk-ok' type="object"/>
</group>
</form>
</field>