[UPDATE] get_warranty on create by invoice

[REMOVE] invoice_line_warranty.py
[FIX] invoice by line
This commit is contained in:
manu
2011-10-14 16:59:36 +02:00
parent c3d494a32e
commit 3d4ad803ef
6 changed files with 69 additions and 97 deletions

View File

@@ -23,4 +23,3 @@
import wizard
import crm_claim_rma
import invoice_line_warranty

View File

@@ -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()

View File

@@ -24,6 +24,7 @@
<openerp>
<data>
<!-- Return line -->
<!-- SEARCH -->
<record id="view_crm_return_lines_filter" model="ir.ui.view">
<field name="name">CRM - Claims Search</field>
<field name="model">return.line</field>
@@ -69,8 +70,8 @@
</search>
</field>
</record>
<!-- TREE -->
<record model="ir.ui.view" id="crm_return_line_tree_view">
<field name="name">CRM - Claims Tree</field>
<field name="model">return.line</field>
@@ -91,6 +92,7 @@
</field>
</record>
<!-- FORM -->
<record model="ir.ui.view" id="crm_return_line_form_view">
<field name="name">CRM - Claim product return line Form</field>
<field name="model">return.line</field>
@@ -115,7 +117,7 @@
<field name="guarantee_limit"/>
<field name="warning"/>
<field name="warranty_return_partner"/>
<!-- field name="guarantee_type"/ -->
<field name="warranty_type"/>
<separator string="State" colspan="4"/>
<group col="6" colspan="4">
<field name="state"/>
@@ -127,7 +129,7 @@
</record>
<!-- Picking follow -->
<!-- TREE -->
<record model="ir.ui.view" id="crm_picking_follow_tree_view">
<field name="name">CRM - Picking follow Tree</field>
<field name="model">picking.follow</field>
@@ -143,21 +145,23 @@
</field>
</record>
<!-- FORM -->
<record model="ir.ui.view" id="crm_picking_follow_form_view">
<field name="name">CRM - Picking follow Form</field>
<field name="model">picking.follow</field>
<field name="arch" type="xml">
<form string="Picking follow">
<field name="picking_id"/>
<field name="related_picking_state"/>
<field name="related_picking_due_date"/>
<field name="related_picking_delivered_date"/>
<field name="name"/>
</form>
<form string="Picking follow">
<field name="picking_id"/>
<field name="related_picking_state"/>
<field name="related_picking_due_date"/>
<field name="related_picking_delivered_date"/>
<field name="name"/>
</form>
</field>
</record>
<!-- PRODUCT EXCHANGE -->
<!-- TREE -->
<record model="ir.ui.view" id="crm_product_exchange_tree_view">
<field name="name">CRM - Product exchange Tree</field>
<field name="model">product.exchange</field>
@@ -178,6 +182,7 @@
</field>
</record>
<!-- FORM -->
<record model="ir.ui.view" id="crm_product_exchange_form_view">
<field name="name">CRM - Product exchange Form</field>
<field name="model">product.exchange</field>

View File

@@ -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 <http://www.gnu.org/licenses/>. #
#########################################################################
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()

View File

@@ -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()

View File

@@ -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: