From 3d4ad803ef505c568fad584fe59cd4489c5e2cb8 Mon Sep 17 00:00:00 2001 From: manu Date: Fri, 14 Oct 2011 16:59:36 +0200 Subject: [PATCH] [UPDATE] get_warranty on create by invoice [REMOVE] invoice_line_warranty.py [FIX] invoice by line --- crm_claim_rma/__init__.py | 1 - crm_claim_rma/crm_claim_rma.py | 52 ++++++++++++------- crm_claim_rma/crm_claim_rma_view.xml | 27 ++++++---- crm_claim_rma/invoice_line_warranty.py | 47 ----------------- .../wizard/returned_lines_from_invoice.py | 34 ++++++------ product_warranty/product_warranty.py | 5 +- 6 files changed, 69 insertions(+), 97 deletions(-) delete mode 100644 crm_claim_rma/invoice_line_warranty.py diff --git a/crm_claim_rma/__init__.py b/crm_claim_rma/__init__.py index 727f7842..14e4b193 100644 --- a/crm_claim_rma/__init__.py +++ b/crm_claim_rma/__init__.py @@ -23,4 +23,3 @@ import wizard import crm_claim_rma -import invoice_line_warranty diff --git a/crm_claim_rma/crm_claim_rma.py b/crm_claim_rma/crm_claim_rma.py index 60de7cef..4d4542a1 100644 --- a/crm_claim_rma/crm_claim_rma.py +++ b/crm_claim_rma/crm_claim_rma.py @@ -26,8 +26,9 @@ from crm import crm from datetime import datetime from dateutil.relativedelta import relativedelta import time +from tools.translate import _ -#===== TO REFACTOR IN A GENERIC MODULE +#===== TO REFACTORED IN A GENERIC MODULE class substate_substate(osv.osv): """ To precise a state (state=refused; substates= reason 1, 2,...) @@ -82,6 +83,7 @@ class return_line(osv.osv): 'applicable_guarantee': fields.selection([('us','Us'),('supplier','Supplier'),('brand','Brand manufacturer')], 'Warranty type'),# METTRE CHAMP FONCTION; type supplier might generate an auto draft forward to the supplier 'guarantee_limit': fields.date('Warranty limit', help="The warranty limit is computed as: invoice date + warranty defined on selected product.", readonly=True), 'warning': fields.char('Warranty', size=64, readonly=True,help="If warranty has expired"), #select=1, + 'warranty_type': fields.char('Warranty type', size=64, readonly=True,help="from product form"), "warranty_return_partner" : fields.many2one('res.partner.address', 'Warranty return',help="Where the customer has to send back the product(s)"), 'claim_id': fields.many2one('crm.claim', 'Related claim',help="To link to the case.claim object"), 'selected' : fields.boolean('s', help="Check to select"), @@ -113,50 +115,60 @@ class return_line(osv.osv): return True # Method to return the partner delivery address or if none, the default address - def _get_partner_address(self, cr, uid, ids, context,partner): - print "IN GET COMP" - print "partner: ",partner - delivery_address_id = self.pool.get('res.partner.address').search(cr, uid, [('partner_id','=',partner.id),('type','like','delivery')]) - if delivery_address_id: - print delivery_address_id - return delivery_address_id - else: - print "default address : ",self.pool.get('res.partner.address').search(cr, uid, [('partner_id','=',partner.id),('type','like','default')]) - return self.pool.get('res.partner.address').search(cr, uid, [('partner_id','=',partner.id),('type','like','default')]) + def _get_partner_address(self, cr, uid, ids, context,partner): + # dedicated_delivery_address stand for the case a new type of address more particularly dedicated to return delivery would be implemented. + dedicated_delivery_address_id = self.pool.get('res.partner.address').search(cr, uid, [('partner_id','=',partner.id),('type','like','dedicated_delivery')]) + if dedicated_delivery_address_id: + return dedicated_delivery_address_id + else: + delivery_address_id = self.pool.get('res.partner.address').search(cr, uid, [('partner_id','=',partner.id),('type','like','delivery')]) + if delivery_address_id: # if delivery address set, use it + return delivery_address_id + else: + default_address_id = self.pool.get('res.partner.address').search(cr, uid, [('partner_id','=',partner.id),('type','like','default')]) + if default_address_id: # if default address set, use it + return default_address_id + else: + raise osv.except_osv(_('Error !'), _('Cannot find any address for this product partner !')) # Method to calculate warranty return address def set_warranty_return_address(self, cr, uid, ids,context,return_line): - print "IN WAR ADDRESS : ",return_line return_address = None + warranty_type = 'company' if return_line.prodlot_id : # multi supplier method - print "true" + print "TO BE IMPLEMENTED" else : # first supplier method if return_line.product_id.seller_ids[0]: if return_line.product_id.seller_ids[0].warranty_return_partner: return_partner = return_line.product_id.seller_ids[0].warranty_return_partner - print "adresse retour : ",return_partner if return_partner == 'company': return_address = self._get_partner_address(cr, uid, ids, context,return_line.claim_id.company_id.partner_id)[0] elif return_partner == 'supplier': return_address = self._get_partner_address(cr, uid, ids, context,return_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, return_line.product_id.product_brand_id.partner_id)[0] + warranty_type = 'brand' else : - print "brand" + warranty_type = 'other' + # TO BE IMPLEMENTED if something to do... else : - print "popup erreur suppl" -# raise osv.except - self.write(cr,uid,ids,{'warranty_return_partner' : return_address}) + raise osv.except_osv(_('Error !'), _('Cannot find any warranty return partner for this product !')) + else : + raise osv.except_osv(_('Error !'), _('Cannot find any supplier for this product !')) + self.write(cr,uid,ids,{'warranty_return_partner':return_address,'warranty_type':warranty_type}) return True # Method to calculate warranty limit and validity - def set_warranty(self, cr, uid, ids,context): + def set_warranty(self, cr, uid, ids,context=None): for return_line in self.browse(cr,uid,ids): if return_line.product_id and return_line.invoice_id: self.set_warranty_limit(cr, uid, ids,context,return_line) self.set_warranty_return_address(cr, uid, ids,context,return_line) else: - self.write(cr,uid,ids,{'warning' : "PLEASE SET PRODUCT & INVOICE",}) + raise osv.except_osv(_('Error !'), _('PLEASE SET PRODUCT & INVOICE!')) return True return_line() diff --git a/crm_claim_rma/crm_claim_rma_view.xml b/crm_claim_rma/crm_claim_rma_view.xml index 63206a24..1b22c48c 100644 --- a/crm_claim_rma/crm_claim_rma_view.xml +++ b/crm_claim_rma/crm_claim_rma_view.xml @@ -24,6 +24,7 @@ + CRM - Claims Search return.line @@ -69,8 +70,8 @@ - - + + CRM - Claims Tree return.line @@ -91,6 +92,7 @@ + CRM - Claim product return line Form return.line @@ -115,7 +117,7 @@ - + @@ -127,7 +129,7 @@ - + CRM - Picking follow Tree picking.follow @@ -143,21 +145,23 @@ + CRM - Picking follow Form picking.follow -
- - - - - - +
+ + + + + +
+ CRM - Product exchange Tree product.exchange @@ -178,6 +182,7 @@ + CRM - Product exchange Form product.exchange diff --git a/crm_claim_rma/invoice_line_warranty.py b/crm_claim_rma/invoice_line_warranty.py deleted file mode 100644 index 3387496c..00000000 --- a/crm_claim_rma/invoice_line_warranty.py +++ /dev/null @@ -1,47 +0,0 @@ -# -*- coding: utf-8 -*- -######################################################################### -# # -# # -######################################################################### -# # -# Copyright (C) 2009-2011 Akretion, Emmanuel Samyn # -# # -#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 . # -######################################################################### -from osv import fields, osv -from dateutil.relativedelta import relativedelta -import time -from datetime import datetime - -class invoice_line_warranty(osv.osv): - """ - Class to add a method on the invoice line object to return warranty date and statu - """ - _name = "account.invoice.line" - _description = "Add product return functionalities, product exchange and aftersale outsourcing to CRM claim" - _inherit = 'account.invoice.line' - - def get_garantee_limit(self,cr, uid, ids,arg,args,context): - claim = self.pool.get('crm.claim').browse(cr,uid,context['active_id']) - filter = {'value':{'guarantee_limit' : False, 'warning' : False }, 'domain':{}} - filter['value']['guarantee_limit'] = time.strftime('%Y-%m-%d %H:%M:%S') - filter['value']['warning'] = 'Valid' - for invoice_line in self.browse(cr,uid,ids): - if invoice_line.product_id.warranty: - filter['value']['guarantee_limit'] = (datetime.strptime(invoice_line.invoice_id.date_invoice, '%Y-%m-%d') + relativedelta(months=int(invoice_line.product_id.warranty))).strftime('%Y-%m-%d') - if filter['value']['guarantee_limit'] < claim.date: - filter['value']['warning'] = 'Expired' - return filter - -invoice_line_warranty() diff --git a/crm_claim_rma/wizard/returned_lines_from_invoice.py b/crm_claim_rma/wizard/returned_lines_from_invoice.py index 091edcd8..d28d6f7b 100644 --- a/crm_claim_rma/wizard/returned_lines_from_invoice.py +++ b/crm_claim_rma/wizard/returned_lines_from_invoice.py @@ -58,22 +58,20 @@ class returned_lines_from_invoice_invoice(osv.osv_memory): invoice_lines_ids = invoice_line_pool.search(cr, uid, [('invoice_id', '=', inv_id)]) # Get invoice lines from invoice line ids for invoice_line in invoice_line_pool.browse(cr,uid,invoice_lines_ids): - context - warranty = invoice_line.get_garantee_limit(cr, uid, context) - self.pool.get('return.line').create(cr, uid, { - 'name' : "none", + return_line_pool = self.pool.get('return.line') + line_id = return_line_pool.create(cr, uid, { + 'claim_origine' : "none", 'invoice_id' : invoice_line.invoice_id.id, 'product_id' : invoice_line.product_id.id, 'product_returned_quantity' : invoice_line.quantity, 'unit_sale_price' : invoice_line.price_unit, #'prodlot_id' : invoice_line., - #'guarantee_type': - 'guarantee_limit' : warranty['value']['guarantee_limit'], - 'warning' : warranty['value']['warning'], 'claim_id' : context['active_id'], 'selected' : False, 'state' : 'draft', }) + for line in return_line_pool.browse(cr,uid,[line_id],context): + line.set_warranty() return {'type': 'ir.actions.act_window_close',} # If "Select lines" button pressed @@ -111,12 +109,13 @@ class returned_lines_from_invoice_lines(osv.osv_memory): # Create return lines from invoice lines for invoice_line in self.pool.get('account.invoice.line').browse(cr,uid,invoice_lines_ids): M2M.append(self.pool.get('temp.return.line').create(cr, uid, { - 'name' : "none", + 'claim_origine' : "none", 'invoice_id' : invoice_line.invoice_id.id, 'invoice_line_id' : invoice_line.id, 'product_id' : invoice_line.product_id.id, 'product_returned_quantity' : invoice_line.quantity, #'prodlot_id' : invoice_line., + 'price_unit': invoice_line.price_unit, })) return M2M @@ -132,21 +131,21 @@ class returned_lines_from_invoice_lines(osv.osv_memory): def action_create_returns(self, cr, uid, ids, context=None): for wiz_obj in self.browse(cr,uid,ids): for line in wiz_obj.return_line_ids: - warranty = line.invoice_line_id.get_garantee_limit(cr, uid, context) - self.pool.get('return.line').create(cr, uid, { - 'name' : line.name, + return_line_pool = self.pool.get('return.line') + line_id = return_line_pool.create(cr, uid, { + 'claim_origine' : line.claim_origine, 'invoice_id' : line.invoice_id.id, 'product_id' : line.product_id.id, 'product_returned_quantity' : line.product_returned_quantity, - 'unit_sale_price' : invoice_line.price_unit, + 'unit_sale_price' : line.price_unit, #'prodlot_id' : invoice_line., - #'guarantee_type': - 'guarantee_limit' : warranty['value']['guarantee_limit'], - 'warning' : warranty['value']['warning'], 'claim_id' : context['active_id'], 'selected' : False, 'state' : 'draft', - }) + }) + for line in return_line_pool.browse(cr,uid,[line_id],context): + line.set_warranty() + return { 'type': 'ir.actions.act_window_close', } @@ -161,7 +160,7 @@ class temp_return_line(osv.osv_memory): _name = "temp.return.line" _description = "List of product to return" _columns = { - 'name': fields.selection([('none','Not specified'), + 'claim_origine': fields.selection([('none','Not specified'), ('legal','Legal retractation'), ('cancellation','Order cancellation'), ('damaged','Damaged delivered product'), @@ -174,6 +173,7 @@ class temp_return_line(osv.osv_memory): 'product_id': fields.many2one('product.product', 'Product'), 'product_returned_quantity' : fields.float('Returned quantity', digits=(12,2), help="Quantity of product returned"), 'prodlot_id': fields.many2one('stock.production.lot', 'Serial / Lot Number'), + 'price_unit': fields.float('Unit sale price', digits=(12,2),), } temp_return_line() diff --git a/product_warranty/product_warranty.py b/product_warranty/product_warranty.py index 3123069a..41a11212 100644 --- a/product_warranty/product_warranty.py +++ b/product_warranty/product_warranty.py @@ -42,7 +42,10 @@ class product_supplierinfo(osv.osv): "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, 'Warrantee return', size=128, 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 applied is the one of the return partner (ie: can be returned to the company and be under the brand warranty"), } - + _defaults = { + 'warranty_return_partner': lambda *a: 'company', + } + product_supplierinfo() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: