[IMP] Little fix on product_waranty

[IMP] Move New Product Loss button from crm_claim_rma to crm_rma_advance_location
[IMP] Add field location_dest_id on claim line and adapt wizar of return with it
This commit is contained in:
Joel Grand-Guillaume
2013-11-14 12:07:38 +01:00
parent 3d88918057
commit 086b8203c0
7 changed files with 242 additions and 58 deletions

View File

@@ -153,6 +153,9 @@ class claim_line(orm.Model):
'move_out_id': fields.many2one('stock.move',
'Move Line from picking out',
help='The move line related to the returned product'),
'location_dest_id': fields.many2one('stock.location',
'Return Stock Location',
help='The return stock location of the returned product'),
}
_defaults = {
@@ -197,50 +200,30 @@ class claim_line(orm.Model):
# Method to calculate warranty return address
def set_warranty_return_address(self, cr, uid, ids,
claim_line, context=None):
"""Return the partner to be used as return destination and
the destination stock location of the line in case of return.
We can have various case here:
- company or other: return to company partner or crm_return_address_id
if specified
- supplier: return to the supplier address"""
return_address = None
warranty_type = 'company'
location_dest_id = claim_line.warehouse_id.lot_stock_id.id
return_type = 'company'
seller = claim_line.product_id.seller_info_id
claim_company = claim_line.claim_id.company_id
if claim_company.crm_return_address_id:
return_address = claim_company.crm_return_address_id.id
else:
return_address = claim_company.partner_id.id
if seller:
return_partner = seller.warranty_return_partner
if return_partner:
warranty_type = return_partner
else:
warranty_type = 'company'
return_address = seller.warranty_return_address.id
# if return_partner == 'company':
# return_address = self._get_partner_address(cr, uid, ids, context,claim_line.claim_id.company_id.partner_id)[0]
# elif return_partner == 'supplier':
# return_address = self._get_partner_address(cr, uid, ids, context,claim_line.product_id.seller_ids[0].name)[0]
# warranty_type = 'supplier'
# elif return_partner == 'brand':
# return_address = self._get_partner_address(cr, uid, ids, context, claim_line.product_id.product_brand_id.partner_id)[0]
# warranty_type = 'brand'
# else :
# warranty_type = 'other'
# # TO BE IMPLEMENTED if something to do...
# else :
# warranty_type = 'company'
# return_address = self._get_default_company_address(cr, uid, claim_line.claim_id.company_id, context=context)
#TODO fix me use default address
# self.write(cr,uid,ids,{'warranty_return_partner':1,'warranty_type': 'company'})
# return True
#raise osv.except_osv(_('Error !'), _('Cannot find any warranty return partner for this product !'))
else :
warranty_type = 'company'
if claim_company.crm_return_address_id:
return_address = [claim_company.crm_return_address_id.id]
else:
return_address = [claim_company.partner_id.address[0].id]
# return_address = self._get_default_company_address(cr, uid, claim_line.claim_id.company_id, context=context)
#TODO fix me use default address
# self.write(cr,uid,ids,{'warranty_return_partner':1,'warranty_type': 'company'})
# return True
#raise osv.except_osv(_('Error !'), _('Cannot find any supplier for this product !'))
return_type = seller.warranty_return_partner
if return_type == 'supplier':
return_address = seller.warranty_return_address.id
location_dest_id = seller.property_stock_supplier.id
self.write(cr, uid, ids,
{'warranty_return_partner':return_address,
'warranty_type':warranty_type})
{'warranty_return_partner': return_address,
'warranty_type': return_type,
'location_dest_id': location_dest_id})
return True
# Method to calculate warranty limit and address

View File

@@ -61,6 +61,7 @@
<field name="product_id"/>
<field name="prodlot_id"/>
<field name="warning"/>
<field name="location_dest_id"/>
<button name="set_warranty" string="Compute Waranty" type="object" icon="gtk-justify-fill"/>
<field name="product_returned_quantity"/>
<field name="claim_origine"/>
@@ -156,25 +157,17 @@
<group col="4" colspan="4" attrs="{'invisible':[('state', '&lt;&gt;','open')]}">
<separator string="Action" colspan="4" />
<button name="%(action_claim_picking_in)d"
string="New picking IN" states="open"
string="New Products Return" states="open"
type="action" target="new"
context="{'warehouse_id': warehouse_id,
'partner_id': partner_id}"/>
<button name="%(action_claim_picking_out)d"
string="New picking OUT" states="open"
string="New Delivery" states="open"
type="action" target="new"
context="{'warehouse_id': warehouse_id,
'partner_id': partner_id}"/>
<button name="%(action_claim_picking_loss)d"
string="New Product Loss" states="open"
type="action" target="new"
context="{'warehouse_id': warehouse_id,
'partner_id': partner_id}"/>
<button name="%(account.action_account_invoice_refund)d"
type='action' string='New Refund'
states='open' icon="gtk-execute"

View File

@@ -84,8 +84,25 @@ class claim_make_picking(orm.TransientModel):
context=context)['property_stock_customer']
return loc_id
def _get_common_dest_location_from_line(self, cr, uid, line_ids, context):
"""Return the ID of the common location between all lines. If notecommon
destination was found, return False"""
loc_id = False
line_obj = self.pool.get('claim.line')
line_location = []
for line in line_obj.browse(cr, uid, line_ids, context=context):
if line.location_dest_id.id not in line_location:
line_location.append(line.location_dest_id.id)
if len (line_location) == 1:
loc_id = line_location[0]
return loc_id
# Get default destination location
def _get_dest_loc(self, cr, uid, context):
"""Return the location_id to use as destination.
If it's an outoing shippment: take the customer stock property
If it's an incomming shippment take the location_dest_id common to all lines, or
if different, return None."""
if context is None: context = {}
warehouse_obj = self.pool.get('stock.warehouse')
warehouse_id = context.get('warehouse_id')
@@ -96,11 +113,10 @@ class claim_make_picking(orm.TransientModel):
['property_stock_customer'],
context=context)['property_stock_customer'][0]
elif context.get('picking_type') == 'in' and context.get('partner_id'):
loc_id = warehouse_obj.read(cr, uid,
warehouse_id,
['lot_stock_id'],
context=context)['lot_stock_id'][0]
# Add the case of return to supplier !
# Add the case of return to supplier !
line_ids = self._get_claim_lines(cr, uid, context=context)
loc_id = self._get_common_dest_location_from_line(cr, uid,
line_ids, context=context)
return loc_id
_defaults = {
@@ -141,6 +157,13 @@ class claim_make_picking(orm.TransientModel):
claim = self.pool.get('crm.claim').browse(cr, uid,
context['active_id'], context=context)
partner_id = claim.partner_id.id
common_dest_loc_id = self._get_common_dest_location_from_line(cr, uid,
line_ids, context=context)
if not common_dest_loc_id:
raise osv.except_osv(_('Error !'),
_('A picking cannot be created for various destination location, please '
'chose line with a same destination location.'))
# create picking
picking_id = picking_obj.create(cr, uid, {
'origin': claim.number,

View File

@@ -0,0 +1,164 @@
# -*- 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 openerp.osv import fields, orm
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
from openerp import netsvc
import time
class claim_make_picking_from_picking(orm.TransientModel):
_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')
print 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),
'partner_id': prev_picking.partner_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,
})
# 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,
'partner_id': prev_picking.partner_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])
domain = "[('type','=','%s'),('partner_id','=',%s)]"%(p_type, partner_id)
return {
'name': '%s' % name,
'view_type': 'form',
'view_mode': 'form',
'view_id': view_id,
'domain' : domain,
'res_model': 'stock.picking',
'res_id': picking_id,
'type': 'ir.actions.act_window',
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -56,6 +56,7 @@ WARNING: This module is currently not yet completely debugged and is waiting his
'data': [
'stock_view.xml',
'stock_data.xml',
'claim_rma_view.xml',
'wizard/claim_make_picking_from_picking_view.xml',
'wizard/claim_make_picking_view.xml',
],

View File

@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<openerp>
<data>
<record model="ir.ui.view" id="crm_claim_rma_form_view">
<field name="name">CRM - Claim product return Form</field>
<field name="model">crm.claim</field>
<field name="inherit_id" ref="crm_claim.crm_case_claims_form_view"/>
<field name="arch" type="xml">
<xpath expr="//button[@string='New Delivery']" position="after">
<button name="%(action_claim_picking_loss)d"
string="New Product Loss" states="open"
type="action" target="new"
context="{'warehouse_id': warehouse_id,
'partner_id': partner_id}"/>
</xpath>
</field>
</record>
</data>
</openerp>

View File

@@ -73,13 +73,13 @@ class product_supplierinfo(orm.Model):
return result
_columns = {
"warranty_duration" : fields.float('Warranty',
"warranty_duration": fields.float('Warranty',
help="Warranty in month for this product/supplier relation. Only for "
"company/supplier relation (purchase order) ; the customer/company "
"relation (sale order) always use the product main warranty field"),
"warranty_return_partner" : fields.selection(get_warranty_return_partner,
"warranty_return_partner": fields.selection(get_warranty_return_partner,
'Warrantee return',
size=128,
required=True,
help="Who is in charge of the warranty return treatment toward the end customer. "
"Company will use the current compagny delivery or default address and so on for "
"supplier and brand manufacturer. Doesn't necessarly mean that the warranty to be "
@@ -88,7 +88,7 @@ class product_supplierinfo(orm.Model):
'return_instructions': fields.many2one('return.instruction',
'Instructions',
help="Instructions for product return"),
'active_supplier' : fields.boolean('Active supplier'),
'active_supplier': fields.boolean('Active supplier'),
'warranty_return_address': fields.function(_get_warranty_return_address,
type='many2one', relation='res.partner', string="Warranty return address"),
}