[MRG] Upgrade to v7

This commit is contained in:
Maxime Chambreuil
2013-08-23 10:16:05 -04:00
8 changed files with 81 additions and 176 deletions

View File

@@ -21,7 +21,7 @@
#along with this program. If not, see <http://www.gnu.org/licenses/>. # #along with this program. If not, see <http://www.gnu.org/licenses/>. #
######################################################################### #########################################################################
from osv import fields, osv from openerp.osv import fields, orm
from crm import crm from crm import crm
from datetime import datetime from datetime import datetime
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
@@ -29,8 +29,8 @@ import time
from tools.translate import _ from tools.translate import _
from tools import DEFAULT_SERVER_DATE_FORMAT from tools import DEFAULT_SERVER_DATE_FORMAT
#===== TO REFACTORED IN A GENERIC MODULE #TODO: REFACTOR IN A GENERIC MODULE
class substate_substate(osv.osv): class substate_substate(orm.Model):
""" """
To precise a state (state=refused; substates= reason 1, 2,...) To precise a state (state=refused; substates= reason 1, 2,...)
""" """
@@ -41,10 +41,8 @@ class substate_substate(osv.osv):
'substate_descr' : fields.text('Description', help="To give more information about the sub state"), 'substate_descr' : fields.text('Description', help="To give more information about the sub state"),
# ADD OBJECT TO FILTER # ADD OBJECT TO FILTER
} }
substate_substate()
#===== class claim_line(orm.Model):
class claim_line(osv.osv):
""" """
Class to handle a product return line (corresponding to one invoice line) Class to handle a product return line (corresponding to one invoice line)
""" """
@@ -52,21 +50,14 @@ class claim_line(osv.osv):
_description = "List of product to return" _description = "List of product to return"
# Method to calculate total amount of the line : qty*UP # Method to calculate total amount of the line : qty*UP
def _line_total_amount(self, cr, uid, ids, field_name, arg,context): def _line_total_amount(self, cr, uid, ids, field_name, arg, context=None):
res = {} res = {}
for line in self.browse(cr,uid,ids): for line in self.browse(cr,uid,ids):
res[line.id] = line.unit_sale_price*line.product_returned_quantity res[line.id] = line.unit_sale_price*line.product_returned_quantity
return res return res
# def _get_claim_seq(self, cr, uid, ids, field_name, arg,context):
# res = {}
# for line in self.browse(cr,uid,ids):
# res[line.id] = line.claim_id.sequence
# return res
_columns = { _columns = {
'name': fields.char('Description', size=64,required=True), 'name': fields.char('Description', size=64,required=True),
# 'name': fields.function(_get_claim_seq, method=True, string='Claim n°', type='char', size=64,store=True),
'claim_origine': fields.selection([('none','Not specified'), 'claim_origine': fields.selection([('none','Not specified'),
('legal','Legal retractation'), ('legal','Legal retractation'),
('cancellation','Order cancellation'), ('cancellation','Order cancellation'),
@@ -76,17 +67,14 @@ class claim_line(osv.osv):
('lost','Lost during transport'), ('lost','Lost during transport'),
('other','Other')], 'Claim Subject', required=True, help="To describe the line product problem"), ('other','Other')], 'Claim Subject', required=True, help="To describe the line product problem"),
'claim_descr' : fields.text('Claim description', help="More precise description of the problem"), 'claim_descr' : fields.text('Claim description', help="More precise description of the problem"),
#use the invoice line instead of the invoice
# 'invoice_id': fields.many2one('account.invoice', 'Invoice',help="The invoice related to the returned product"),
'product_id': fields.many2one('product.product', 'Product',help="Returned product"), 'product_id': fields.many2one('product.product', 'Product',help="Returned product"),
'product_returned_quantity' : fields.float('Quantity', digits=(12,2), help="Quantity of product returned"), 'product_returned_quantity' : fields.float('Quantity', digits=(12,2), help="Quantity of product returned"),
'unit_sale_price' : fields.float('Unit sale price', digits=(12,2), help="Unit sale price of the product. Auto filed if retrun done by invoice selection. BE CAREFUL AND CHECK the automatic value as don't take into account previous refounds, invoice discount, can be for 0 if product for free,..."), 'unit_sale_price' : fields.float('Unit sale price', digits=(12,2), help="Unit sale price of the product. Auto filed if retrun done by invoice selection. BE CAREFUL AND CHECK the automatic value as don't take into account previous refounds, invoice discount, can be for 0 if product for free,..."),
'return_value' : fields.function(_line_total_amount, method=True, string='Total return', type='float', help="Quantity returned * Unit sold price",), 'return_value' : fields.function(_line_total_amount, method=True, string='Total return', type='float', help="Quantity returned * Unit sold price",),
'prodlot_id': fields.many2one('stock.production.lot', 'Serial/Lot n°',help="The serial/lot of the returned product"), 'prodlot_id': fields.many2one('stock.production.lot', 'Serial/Lot n°',help="The serial/lot of the returned product"),
'applicable_guarantee': fields.selection([('us','Company'),('supplier','Supplier'),('brand','Brand manufacturer')], 'Warranty type'),# METTRE CHAMP FONCTION; type supplier might generate an auto draft forward to the supplier 'applicable_guarantee': fields.selection([('us','Company'),('supplier','Supplier'),('brand','Brand manufacturer')], 'Warranty type'),# TODO: Replace with function field. 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), '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, 'warning': fields.char('Warranty', size=64, readonly=True,help="If warranty has expired"),
'warranty_type': fields.char('Warranty type', size=64, readonly=True,help="from product form"), 'warranty_type': fields.char('Warranty type', size=64, readonly=True,help="from product form"),
"warranty_return_partner" : fields.many2one('res.partner', 'Warranty return',help="Where the customer has to send back the product(s)"), "warranty_return_partner" : fields.many2one('res.partner', '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"), 'claim_id': fields.many2one('crm.claim', 'Related claim',help="To link to the case.claim object"),
@@ -110,13 +98,13 @@ class claim_line(osv.osv):
} }
# Method to calculate warranty limit # Method to calculate warranty limit
def set_warranty_limit(self, cr, uid, ids, context, claim_line): def set_warranty_limit(self, cr, uid, ids, claim_line, context=None):
date_invoice = claim_line.invoice_line_id.invoice_id.date_invoice date_invoice = claim_line.invoice_line_id.invoice_id.date_invoice
if date_invoice: if date_invoice:
warning = "Valid" warning = "Valid"
if claim_line.claim_id.claim_type == 'supplier': if claim_line.claim_id.claim_type == 'supplier':
if claim_line.prodlot_id : if claim_line.prodlot_id :
limit = (datetime.strptime(date_invoice, DEFAULT_SERVER_DATE_FORMAT) + relativedelta(months=int(claim_line.product_id.seller_ids[0].warranty_duration))).strftime(DEFAULT_SERVER_DATE_FORMAT) # TO BE IMPLEMENTED !!! limit = (datetime.strptime(date_invoice, DEFAULT_SERVER_DATE_FORMAT) + relativedelta(months=int(claim_line.product_id.seller_ids[0].warranty_duration))).strftime(DEFAULT_SERVER_DATE_FORMAT) # TODO: To be implemented
else : else :
limit = (datetime.strptime(date_invoice, DEFAULT_SERVER_DATE_FORMAT) + relativedelta(months=int(claim_line.product_id.seller_ids[0].warranty_duration))).strftime(DEFAULT_SERVER_DATE_FORMAT) limit = (datetime.strptime(date_invoice, DEFAULT_SERVER_DATE_FORMAT) + relativedelta(months=int(claim_line.product_id.seller_ids[0].warranty_duration))).strftime(DEFAULT_SERVER_DATE_FORMAT)
else : else :
@@ -132,7 +120,7 @@ class claim_line(osv.osv):
return True return True
# Method to calculate warranty return address # Method to calculate warranty return address
def set_warranty_return_address(self, cr, uid, ids, context, claim_line): def set_warranty_return_address(self, cr, uid, ids, claim_line, context=None):
return_address = None return_address = None
warranty_type = 'company' warranty_type = 'company'
seller = claim_line.product_id.seller_info_id seller = claim_line.product_id.seller_info_id
@@ -177,76 +165,18 @@ class claim_line(osv.osv):
return True return True
# Method to calculate warranty limit and validity # Method to calculate warranty limit and validity
def set_warranty(self, cr, uid, ids,context=None): def set_warranty(self, cr, uid, ids, context=None):
for claim_line in self.browse(cr, uid, ids, context=context): for claim_line in self.browse(cr, uid, ids, context=context):
if claim_line.product_id and claim_line.invoice_line_id: if claim_line.product_id and claim_line.invoice_line_id:
self.set_warranty_limit(cr, uid, ids, context, claim_line) self.set_warranty_limit(cr, uid, ids, claim_line, context)
self.set_warranty_return_address(cr, uid, ids, context, claim_line) self.set_warranty_return_address(cr, uid, ids, claim_line, context)
else: else:
raise osv.except_osv(_('Error !'), _('PLEASE SET PRODUCT & INVOICE!')) raise osv.except_osv(_('Error !'), _('PLEASE SET PRODUCT & INVOICE!'))
return True return True
#TODO add the option split the claim_line in order to manage the same product separately #TODO add the option to split the claim_line in order to manage the same product separately
claim_line() class crm_claim(orm.Model):
#===== deprecated everything is based on the claim_line so product_exchange is useless
#class product_exchange(osv.osv):
# """
# Class to manage product exchanges history
# """
# _name = "product.exchange"
# _description = "exchange history line"
#
# # Method to calculate total amount of the line : qty*UP
# def total_amount_returned(self, cr, uid, ids, field_name, arg,context):
# res = {}
# for line in self.browse(cr,uid,ids):
# res[line.id] = line.returned_unit_sale_price*line.returned_product_qty
# return res
# # Method to calculate total amount of the line : qty*UP
# def total_amount_replacement(self, cr, uid, ids, field_name, arg,context):
# res = {}
# for line in self.browse(cr,uid,ids):
# res[line.id] = line.replacement_unit_sale_price*line.replacement_product_qty
# return res
# # Method to get the replacement product unit price
# def get_replacement_price(self, cr, uid, ids, field_name, arg,context):
# res = {}
# for line in self.browse(cr,uid,ids):
# res[line.id] = line.replacement_product.list_price
# return res
#
# _columns = {
# 'name': fields.char('Comment', size=128, required=True),
# 'exchange_send_date' : fields.date('Exchange date'),
# 'returned_product' : fields.many2one('product.product', 'Returned product', required=True), # ADD FILTER ON RETURNED PROD
# 'returned_product_serial' : fields.many2one('stock.production.lot', 'Returned serial/Lot n°'),
# 'returned_product_qty' : fields.float('Returned quantity', digits=(12,2), help="Quantity of product returned"),
# 'replacement_product' : fields.many2one('product.product', 'Replacement product', required=True),
# 'replacement_product_serial' : fields.many2one('stock.production.lot', 'Replacement serial/Lot n°'),
# 'replacement_product_qty' : fields.float('Replacement quantity', digits=(12,2), help="Quantity of product replaced"),
# 'claim_return_id' : fields.many2one('crm.claim', 'Related claim'), # To link to the case.claim object
# 'selected' : fields.boolean('s', help="Check to select"),
# 'state' : fields.selection([('draft','Draft'),
# ('confirmed','Confirmed'),
# ('to_send','To send'),
# ('sent','Sent')], 'State'),
# 'returned_unit_sale_price' : fields.float('Unit sale price', digits=(12,2)),
# 'returned_value' : fields.function(total_amount_returned, method=True, string='Total return', type='float', help="Quantity exchanged * Unit sold price",),
# 'replacement_unit_sale_price' : fields.function(get_replacement_price, method=True, string='Unit sale price', type='float',),
# 'replacement_value' : fields.function(total_amount_replacement, method=True, string='Total return', type='float', help="Quantity replaced * Unit sold price",),
# }
# _defaults = {
# 'state': lambda *a: 'draft',
# }
#
#product_exchange()
#==========
class crm_claim(osv.osv):
_inherit = 'crm.claim' _inherit = 'crm.claim'
_columns = { _columns = {
@@ -263,8 +193,8 @@ class crm_claim(osv.osv):
# Financial management # Financial management
'planned_revenue': fields.float('Expected revenue'), 'planned_revenue': fields.float('Expected revenue'),
'planned_cost': fields.float('Expected cost'), 'planned_cost': fields.float('Expected cost'),
'real_revenue': fields.float('Real revenue'), # A VOIR SI COMPTA ANA ou lien vers compte ana ? 'real_revenue': fields.float('Real revenue'),
'real_cost': fields.float('Real cost'), # A VOIR SI COMPTA ANA ou lien vers compte ana ? 'real_cost': fields.float('Real cost'),
'invoice_ids': fields.one2many('account.invoice', 'claim_id', 'Refunds'), 'invoice_ids': fields.one2many('account.invoice', 'claim_id', 'Refunds'),
'picking_ids': fields.one2many('stock.picking', 'claim_id', 'RMA'), 'picking_ids': fields.one2many('stock.picking', 'claim_id', 'RMA'),
'invoice_id': fields.many2one('account.invoice', 'Invoice', help='Related invoice'), 'invoice_id': fields.many2one('account.invoice', 'Invoice', help='Related invoice'),
@@ -275,31 +205,8 @@ class crm_claim(osv.osv):
'claim_type': lambda *a: 'customer', 'claim_type': lambda *a: 'customer',
'warehouse_id': lambda *a: 1, 'warehouse_id': lambda *a: 1,
} }
# #===== Method to select all returned lines =====
# def select_all(self,cr, uid, ids,context):
# return_obj = self.pool.get('claim.line')
# for line in self.browse(cr,uid,ids)[0].claim_line_ids:
# return_obj.write(cr,uid,line.id,{'selected':True})
# return True
# #===== Method to unselect all returned lines ===== def onchange_partner_address_id(self, cr, uid, ids, add, email=False, context=None):
# def unselect_all(self,cr, uid, ids,context):
# return_obj = self.pool.get('claim.line')
# for line in self.browse(cr,uid,ids)[0].claim_line_ids:
# return_obj.write(cr,uid,line.id,{'selected':False})
# return True
# === deprecated if we use the refund wizard of the account module ===
# def refund(self, cr, uid, ids, context=None):
# mod_obj = self.pool.get('ir.model.data')
# xml_id = 'action_account_invoice_refund'
# result = mod_obj.get_object_reference(cr, uid, 'account', xml_id)
# id = result and result[1] or False
# result = act_obj.read(cr, uid, id, context=context)
# print 'result', result
# return result
def onchange_partner_address_id(self, cr, uid, ids, add, email=False):
res = super(crm_claim, self).onchange_partner_address_id(cr, uid, ids, add, email=email) res = super(crm_claim, self).onchange_partner_address_id(cr, uid, ids, add, email=email)
if add: if add:
if not res['value']['email_from'] or not res['value']['partner_phone']: if not res['value']['email_from'] or not res['value']['partner_phone']:
@@ -331,6 +238,4 @@ class crm_claim(osv.osv):
# line.set_warranty() # line.set_warranty()
return {'value' : {'claim_line_ids' : claim_lines}} return {'value' : {'claim_line_ids' : claim_lines}}
crm_claim()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -323,15 +323,17 @@
res_model="account.invoice" res_model="account.invoice"
src_model="crm.claim"/> src_model="crm.claim"/>
<!-- Right side link to picking in --> <!-- Right side link to picking in -->
<act_window <act_window
domain="[('type', '=', 'in'),('partner_id', 'in', [partner_id])]" context="{'search_default_partner_id': [partner_id]}"
domain="[('type', '=', 'in')]"
id="act_crm_claim_rma_picking_in" id="act_crm_claim_rma_picking_in"
name="Partner picking IN" name="Partner picking IN"
res_model="stock.picking" res_model="stock.picking"
src_model="crm.claim"/> src_model="crm.claim"/>
<!-- Right side link to picking out --> <!-- Right side link to picking out -->
<act_window <act_window
domain="[('type', '=', 'out'),('partner_id', 'in', [partner_id])]" context="{'search_default_partner_id': [partner_id]}"
domain="[('type', '=', 'out')]"
id="act_crm_claim_rma_picking_out" id="act_crm_claim_rma_picking_out"
name="Partner picking OUT" name="Partner picking OUT"
res_model="stock.picking" res_model="stock.picking"

View File

@@ -116,7 +116,6 @@ class claim_make_picking(osv.osv_memory):
view_name = 'stock.picking.in.form' view_name = 'stock.picking.in.form'
view_id = view_obj.search(cr, uid, [ view_id = view_obj.search(cr, uid, [
('xml_id', '=', view_xml_id), ('xml_id', '=', view_xml_id),
('model', '=', 'stock.picking'),
('type', '=', 'form'), ('type', '=', 'form'),
('name', '=', view_name) ('name', '=', view_name)
], context=context)[0] ], context=context)[0]
@@ -130,7 +129,7 @@ class claim_make_picking(osv.osv_memory):
'move_type': 'one', # direct 'move_type': 'one', # direct
'state': 'draft', 'state': 'draft',
'date': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT), 'date': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
'address_id': claim.partner_address_id.id, 'partner_id': claim.partner_id.id,
'invoice_state': "none", 'invoice_state': "none",
'company_id': claim.company_id.id, 'company_id': claim.company_id.id,
'location_id': wizard.claim_line_source_location.id, 'location_id': wizard.claim_line_source_location.id,
@@ -150,7 +149,7 @@ class claim_make_picking(osv.osv_memory):
'product_id': wizard_claim_line.product_id.id, 'product_id': wizard_claim_line.product_id.id,
'product_qty': wizard_claim_line.product_returned_quantity, 'product_qty': wizard_claim_line.product_returned_quantity,
'product_uom': wizard_claim_line.product_id.uom_id.id, 'product_uom': wizard_claim_line.product_id.uom_id.id,
'address_id': claim.partner_address_id.id, 'partner_id': claim.partner_id.id,
'prodlot_id': wizard_claim_line.prodlot_id.id, 'prodlot_id': wizard_claim_line.prodlot_id.id,
# 'tracking_id': # 'tracking_id':
'picking_id': picking_id, 'picking_id': picking_id,

View File

@@ -93,7 +93,7 @@ class claim_make_picking_from_picking(osv.osv_memory):
'move_type': 'one', # direct 'move_type': 'one', # direct
'state': 'draft', 'state': 'draft',
'date': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT), 'date': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
'address_id': prev_picking.address_id.id, 'partner_id': prev_picking.partner_id.id,
'invoice_state': "none", 'invoice_state': "none",
'company_id': prev_picking.company_id.id, 'company_id': prev_picking.company_id.id,
'location_id': wizard.picking_line_source_location.id, 'location_id': wizard.picking_line_source_location.id,
@@ -112,7 +112,7 @@ class claim_make_picking_from_picking(osv.osv_memory):
'product_id': wizard_picking_line.product_id.id, 'product_id': wizard_picking_line.product_id.id,
'product_qty': wizard_picking_line.product_qty, 'product_qty': wizard_picking_line.product_qty,
'product_uom': wizard_picking_line.product_uom.id, 'product_uom': wizard_picking_line.product_uom.id,
'address_id': prev_picking.address_id.id, 'partner_id': prev_picking.partner_id.id,
'prodlot_id': wizard_picking_line.prodlot_id.id, 'prodlot_id': wizard_picking_line.prodlot_id.id,
# 'tracking_id': # 'tracking_id':
'picking_id': picking_id, 'picking_id': picking_id,

View File

@@ -31,7 +31,7 @@ class picking_out_from_exchange_lines(osv.osv_memory):
_columns = { _columns = {
'exchange_line_ids' : fields.many2many('temp.exchange.line', string='Selected exchange lines'), 'exchange_line_ids' : fields.many2many('temp.exchange.line', string='Selected exchange lines'),
} }
# Get selected lines to add to picking in # Get selected lines to add to picking in
def _get_selected_lines(self, cr, uid,context): def _get_selected_lines(self, cr, uid,context):
exchange_line_ids = self.pool.get('crm.claim').read(cr, uid, context['active_id'], ['product_exchange_ids'])['product_exchange_ids'] exchange_line_ids = self.pool.get('crm.claim').read(cr, uid, context['active_id'], ['product_exchange_ids'])['product_exchange_ids']
@@ -46,13 +46,13 @@ class picking_out_from_exchange_lines(osv.osv_memory):
'returned_prodlot_id' : line.returned_product_serial.id, 'returned_prodlot_id' : line.returned_product_serial.id,
'replacement_product_id': line.replacement_product.id, 'replacement_product_id': line.replacement_product.id,
'replacement_product_quantity' : line.replacement_product_qty, 'replacement_product_quantity' : line.replacement_product_qty,
'replacement_prodlot_id': line.replacement_product_serial.id, 'replacement_prodlot_id': line.replacement_product_serial.id,
})) }))
return M2M return M2M
_defaults = { _defaults = {
'exchange_line_ids': _get_selected_lines, 'exchange_line_ids': _get_selected_lines,
} }
# If "Cancel" button pressed # If "Cancel" button pressed
def action_cancel(self,cr,uid,ids,conect=None): def action_cancel(self,cr,uid,ids,conect=None):
@@ -70,13 +70,13 @@ class picking_out_from_exchange_lines(osv.osv_memory):
'move_type': 'one', # direct 'move_type': 'one', # direct
'state': 'draft', 'state': 'draft',
'date': time.strftime('%Y-%m-%d %H:%M:%S'), 'date': time.strftime('%Y-%m-%d %H:%M:%S'),
'address_id': claim_id.partner_address_id.id, 'partner_id': claim_id.partner_id.id,
'invoice_state': "none", 'invoice_state': "none",
'company_id': claim_id.company_id.id, 'company_id': claim_id.company_id.id,
# 'stock_journal_id': fields.many2one('stock.journal','Stock Journal', select=True), # 'stock_journal_id': fields.many2one('stock.journal','Stock Journal', select=True),
'location_id': self.pool.get('stock.warehouse').read(cr, uid, [1],['lot_input_id'])[0]['lot_input_id'][0], 'location_id': self.pool.get('stock.warehouse').read(cr, uid, [1],['lot_input_id'])[0]['lot_input_id'][0],
'location_dest_id': claim_id.partner_id.property_stock_customer.id, 'location_dest_id': claim_id.partner_id.property_stock_customer.id,
'note' : 'RMA picking in', 'note' : 'RMA picking in',
}) })
# Create picking lines # Create picking lines
for exchange_line in exchange_lines.exchange_line_ids: for exchange_line in exchange_lines.exchange_line_ids:
@@ -89,7 +89,7 @@ class picking_out_from_exchange_lines(osv.osv_memory):
'product_id': exchange_line.replacement_product_id.id, 'product_id': exchange_line.replacement_product_id.id,
'product_qty': exchange_line.replacement_product_quantity, 'product_qty': exchange_line.replacement_product_quantity,
'product_uom': exchange_line.replacement_product_id.uom_id.id, 'product_uom': exchange_line.replacement_product_id.uom_id.id,
'address_id': claim_id.partner_address_id.id, 'partner_id': claim_id.partner_id.id,
'prodlot_id': exchange_line.replacement_prodlot_id, 'prodlot_id': exchange_line.replacement_prodlot_id,
# 'tracking_id': # 'tracking_id':
'picking_id': picking_id, 'picking_id': picking_id,
@@ -99,7 +99,7 @@ class picking_out_from_exchange_lines(osv.osv_memory):
'company_id': claim_id.company_id.id, 'company_id': claim_id.company_id.id,
'location_id': self.pool.get('stock.warehouse').read(cr, uid, [1],['lot_input_id'])[0]['lot_input_id'][0], 'location_id': self.pool.get('stock.warehouse').read(cr, uid, [1],['lot_input_id'])[0]['lot_input_id'][0],
'location_dest_id': claim_id.partner_id.property_stock_customer.id, 'location_dest_id': claim_id.partner_id.property_stock_customer.id,
'note': 'RMA Refound', 'note': 'RMA Refound',
}) })
view = { view = {
'name': 'Customer Picking OUT', 'name': 'Customer Picking OUT',
@@ -110,7 +110,7 @@ class picking_out_from_exchange_lines(osv.osv_memory):
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',
} }
return view return view
picking_out_from_exchange_lines() picking_out_from_exchange_lines()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -32,7 +32,7 @@ class picking_in_from_returned_lines(osv.osv_memory):
'claim_line_location' : fields.many2one('stock.location', 'Dest. Location',help="Location where the system will stock the returned products.", select=True), 'claim_line_location' : fields.many2one('stock.location', 'Dest. Location',help="Location where the system will stock the returned products.", select=True),
'claim_line_ids' : fields.many2many('temp.claim.line',string='Selected return lines'), 'claim_line_ids' : fields.many2many('temp.claim.line',string='Selected return lines'),
} }
# Get selected lines to add to picking in # Get selected lines to add to picking in
def _get_selected_lines(self, cr, uid,context): def _get_selected_lines(self, cr, uid,context):
returned_line_ids = self.pool.get('crm.claim').read(cr, uid, context['active_id'], ['claim_line_ids'])['claim_line_ids'] returned_line_ids = self.pool.get('crm.claim').read(cr, uid, context['active_id'], ['claim_line_ids'])['claim_line_ids']
@@ -53,12 +53,12 @@ class picking_in_from_returned_lines(osv.osv_memory):
# Get default destination location # Get default destination location
def _get_dest_loc(self, cr, uid,context): def _get_dest_loc(self, cr, uid,context):
return self.pool.get('stock.warehouse').read(cr, uid, [1],['lot_input_id'])[0]['lot_input_id'][0] return self.pool.get('stock.warehouse').read(cr, uid, [1],['lot_input_id'])[0]['lot_input_id'][0]
_defaults = { _defaults = {
'claim_line_ids': _get_selected_lines, 'claim_line_ids': _get_selected_lines,
'claim_line_location' : _get_dest_loc, 'claim_line_location' : _get_dest_loc,
} }
# If "Cancel" button pressed # If "Cancel" button pressed
def action_cancel(self,cr,uid,ids,conect=None): def action_cancel(self,cr,uid,ids,conect=None):
return {'type': 'ir.actions.act_window_close',} return {'type': 'ir.actions.act_window_close',}
@@ -84,7 +84,7 @@ class picking_in_from_returned_lines(osv.osv_memory):
'move_type': 'one', # direct 'move_type': 'one', # direct
'state': 'draft', 'state': 'draft',
'date': time.strftime('%Y-%m-%d %H:%M:%S'), 'date': time.strftime('%Y-%m-%d %H:%M:%S'),
'address_id': claim_id.partner_address_id.id, 'partner_id': claim_id.partner_id.id,
'invoice_state': "none", 'invoice_state': "none",
'company_id': claim_id.company_id.id, 'company_id': claim_id.company_id.id,
'location_id': location, 'location_id': location,
@@ -103,7 +103,7 @@ class picking_in_from_returned_lines(osv.osv_memory):
'product_id': picking_line.product_id.id, 'product_id': picking_line.product_id.id,
'product_qty': picking_line.product_returned_quantity, 'product_qty': picking_line.product_returned_quantity,
'product_uom': picking_line.product_id.uom_id.id, 'product_uom': picking_line.product_id.uom_id.id,
'address_id': claim_id.partner_address_id.id, 'partner_id': claim_id.partner_id.id,
'prodlot_id': picking_line.prodlot_id.id, 'prodlot_id': picking_line.prodlot_id.id,
# 'tracking_id': # 'tracking_id':
'picking_id': picking_id, 'picking_id': picking_id,
@@ -125,7 +125,7 @@ class picking_in_from_returned_lines(osv.osv_memory):
'res_model': 'stock.picking', 'res_model': 'stock.picking',
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',
} }
picking_in_from_returned_lines() picking_in_from_returned_lines()
# Class to create a picking out from selected return lines # Class to create a picking out from selected return lines
@@ -135,7 +135,7 @@ class picking_out_from_returned_lines(osv.osv_memory):
_columns = { _columns = {
'claim_line_ids' : fields.many2many('temp.claim.line', string='Selected return lines'), 'claim_line_ids' : fields.many2many('temp.claim.line', string='Selected return lines'),
} }
# Get selected lines to add to picking in # Get selected lines to add to picking in
def _get_selected_lines(self, cr, uid,context): def _get_selected_lines(self, cr, uid,context):
returned_line_ids = self.pool.get('crm.claim').read(cr, uid, context['active_id'], ['claim_line_ids'])['claim_line_ids'] returned_line_ids = self.pool.get('crm.claim').read(cr, uid, context['active_id'], ['claim_line_ids'])['claim_line_ids']
@@ -151,11 +151,11 @@ class picking_out_from_returned_lines(osv.osv_memory):
'prodlot_id' : line.prodlot_id.id, 'prodlot_id' : line.prodlot_id.id,
'price_unit' : line.unit_sale_price, 'price_unit' : line.unit_sale_price,
})) }))
return M2M return M2M
_defaults = { _defaults = {
'claim_line_ids': _get_selected_lines, 'claim_line_ids': _get_selected_lines,
} }
# If "Cancel" button pressed # If "Cancel" button pressed
def action_cancel(self,cr,uid,ids,context=None): def action_cancel(self,cr,uid,ids,context=None):
@@ -180,7 +180,7 @@ class picking_out_from_returned_lines(osv.osv_memory):
'move_type': 'one', # direct 'move_type': 'one', # direct
'state': 'draft', 'state': 'draft',
'date': time.strftime('%Y-%m-%d %H:%M:%S'), 'date': time.strftime('%Y-%m-%d %H:%M:%S'),
'address_id': claim_id.partner_address_id.id, 'partner_id': claim_id.partner_id.id,
'invoice_state': "none", 'invoice_state': "none",
'company_id': claim_id.company_id.id, 'company_id': claim_id.company_id.id,
# 'stock_journal_id': fields.many2one('stock.journal','Stock Journal', select=True), # 'stock_journal_id': fields.many2one('stock.journal','Stock Journal', select=True),
@@ -200,7 +200,7 @@ class picking_out_from_returned_lines(osv.osv_memory):
'product_id': picking_line.product_id.id, 'product_id': picking_line.product_id.id,
'product_qty': picking_line.product_returned_quantity, 'product_qty': picking_line.product_returned_quantity,
'product_uom': picking_line.product_id.uom_id.id, 'product_uom': picking_line.product_id.uom_id.id,
'address_id': claim_id.partner_address_id.id, 'partner_id': claim_id.partner_id.id,
'prodlot_id': picking_line.prodlot_id.id, 'prodlot_id': picking_line.prodlot_id.id,
# 'tracking_id': # 'tracking_id':
'picking_id': picking_id, 'picking_id': picking_id,

View File

@@ -31,7 +31,7 @@ class refund_from_returned_lines(osv.osv_memory):
'refund_journal' : fields.many2one('account.journal', 'Refund journal', select=True), 'refund_journal' : fields.many2one('account.journal', 'Refund journal', select=True),
'claim_line_ids' : fields.many2many('temp.claim.line', string='Selected return lines'), 'claim_line_ids' : fields.many2many('temp.claim.line', string='Selected return lines'),
} }
# Get selected lines to add to picking in # Get selected lines to add to picking in
def _get_selected_lines(self, cr, uid,context): def _get_selected_lines(self, cr, uid,context):
returned_line_ids = self.pool.get('crm.claim').read(cr, uid, context['active_id'], ['claim_line_ids'])['claim_line_ids'] returned_line_ids = self.pool.get('crm.claim').read(cr, uid, context['active_id'], ['claim_line_ids'])['claim_line_ids']
@@ -47,18 +47,18 @@ class refund_from_returned_lines(osv.osv_memory):
'prodlot_id' : line.prodlot_id.id, 'prodlot_id' : line.prodlot_id.id,
'price_unit' : line.unit_sale_price, 'price_unit' : line.unit_sale_price,
})) }))
return M2M return M2M
# Get default journal # Get default journal
def _get_journal(self, cr, uid,context): def _get_journal(self, cr, uid,context):
#('company_id','=',claim_id.company_id.id) #('company_id','=',claim_id.company_id.id)
# ,('refund_journal','=','True') # ,('refund_journal','=','True')
return self.pool.get('account.journal').search(cr, uid, [('type','=','sale_refund')],limit=1)[0] return self.pool.get('account.journal').search(cr, uid, [('type','=','sale_refund')],limit=1)[0]
_defaults = { _defaults = {
'claim_line_ids': _get_selected_lines, 'claim_line_ids': _get_selected_lines,
'refund_journal' : _get_journal, 'refund_journal' : _get_journal,
} }
# On "Cancel" button # On "Cancel" button
def action_cancel(self,cr,uid,ids,context=None): def action_cancel(self,cr,uid,ids,context=None):
@@ -85,22 +85,22 @@ class refund_from_returned_lines(osv.osv_memory):
'reference_type': 'none', 'reference_type': 'none',
'date_invoice': time.strftime('%Y-%m-%d %H:%M:%S'), 'date_invoice': time.strftime('%Y-%m-%d %H:%M:%S'),
# 'date_due': # 'date_due':
'address_contact_id' : claim_id.partner_address_id.id, 'partner_id' : claim_id.partner_id.id,
'address_invoice_id' : claim_id.partner_address_id.id, 'commercial_partner_id' : claim_id.partner_id.id,
'account_id' : claim_id.partner_id.property_account_receivable.id, 'account_id' : claim_id.partner_id.property_account_receivable.id,
'currency_id' : claim_id.company_id.currency_id.id, # from invoice ??? 'currency_id' : claim_id.company_id.currency_id.id, # from invoice ???
'journal_id' : refund.refund_journal.id, 'journal_id' : refund.refund_journal.id,
'company_id' : claim_id.company_id.id, 'company_id' : claim_id.company_id.id,
'comment' : 'RMA Refund', 'comment' : 'RMA Refund',
'claim_id': claim_id.id, 'claim_id': claim_id.id,
}) })
# Create invoice lines # Create invoice lines
for refund_line in refund.claim_line_ids: for refund_line in refund.claim_line_ids:
if refund_line.invoice_id: if refund_line.invoice_id:
invoice_line_id = self.pool.get('account.invoice.line').create(cr, uid, { invoice_line_id = self.pool.get('account.invoice.line').create(cr, uid, {
'name' : refund_line.product_id.name_template, 'name' : refund_line.product_id.name_template,
'origin' : claim_id.sequence, 'origin' : claim_id.sequence,
'invoice_id' : invoice_id, 'invoice_id' : invoice_id,
'uos_id' : refund_line.product_id.uom_id.id, 'uos_id' : refund_line.product_id.uom_id.id,
'product_id':refund_line.product_id.id, 'product_id':refund_line.product_id.id,
'account_id': claim_id.partner_id.property_account_receivable.id, # refund_line.product_id.property_account_expense.id, 'account_id': claim_id.partner_id.property_account_receivable.id, # refund_line.product_id.property_account_expense.id,
@@ -111,7 +111,7 @@ class refund_from_returned_lines(osv.osv_memory):
# 'account_analytic_id': # 'account_analytic_id':
'company_id' : claim_id.company_id.id, 'company_id' : claim_id.company_id.id,
'partner_id' : refund_line.invoice_id.partner_id.id, 'partner_id' : refund_line.invoice_id.partner_id.id,
'note': 'RMA Refund', 'note': 'RMA Refund',
}) })
else: else:
raise osv.except_osv(_('Error !'), _('Cannot find any invoice for the return line!')) raise osv.except_osv(_('Error !'), _('Cannot find any invoice for the return line!'))
@@ -123,7 +123,7 @@ class refund_from_returned_lines(osv.osv_memory):
'res_model': 'account.invoice', 'res_model': 'account.invoice',
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',
} }
refund_from_returned_lines() refund_from_returned_lines()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -20,11 +20,10 @@
#along with this program. If not, see <http://www.gnu.org/licenses/>. # #along with this program. If not, see <http://www.gnu.org/licenses/>. #
######################################################################### #########################################################################
from osv import fields, osv from openerp.osv import orm, fields
from tools.translate import _ from tools.translate import _
#===== class return_instruction(orm.Model):
class return_instruction(osv.osv):
_name = "return.instruction" _name = "return.instruction"
_description = "Instructions for product return" _description = "Instructions for product return"
_columns = { _columns = {
@@ -32,10 +31,8 @@ class return_instruction(osv.osv):
'instructions' : fields.text('Instructions', help="Instructions for product return"), 'instructions' : fields.text('Instructions', help="Instructions for product return"),
'is_default' : fields.boolean('Is default', help="If is default, will be use to set the default value in supplier infos. Be careful to have only one default"), 'is_default' : fields.boolean('Is default', help="If is default, will be use to set the default value in supplier infos. Be careful to have only one default"),
} }
return_instruction()
#===== class product_supplierinfo(orm.Model):
class product_supplierinfo(osv.osv):
_inherit = "product.supplierinfo" _inherit = "product.supplierinfo"
def get_warranty_return_partner(self, cr, uid, context=None): def get_warranty_return_partner(self, cr, uid, context=None):
@@ -48,18 +45,18 @@ class product_supplierinfo(osv.osv):
return result return result
# Get selected lines to add to exchange # Get selected lines to add to exchange
def _get_default_instructions(self, cr, uid,context): def _get_default_instructions(self, cr, uid, context=None):
instruction_ids = self.pool.get('return.instruction').search(cr, uid, [('is_default','=','FALSE')]) instruction_ids = self.pool.get('return.instruction').search(cr, uid, [('is_default','=','FALSE')])
if instruction_ids: if instruction_ids:
return instruction_ids[0] return instruction_ids[0]
# TO DO f(supplier) + other. # TODO f(supplier) + other.
return False return False
def _get_warranty_return_address(self, cr, uid, ids, field_names, arg, context=None): def _get_warranty_return_address(self, cr, uid, ids, field_names, arg, context=None):
# Method to return the partner delivery address or if none, the default address # Method to return the partner delivery address or if none, the default address
# dedicated_delivery_address stand for the case a new type of address more particularly dedicated to return delivery would be implemented. # dedicated_delivery_address stand for the case a new type of address more particularly dedicated to return delivery would be implemented.
result ={} result ={}
address_obj = self.pool.get('res.partner.address') address_obj = self.pool.get('res.partner')
for supplier_info in self.browse(cr, uid, ids, context=context): for supplier_info in self.browse(cr, uid, ids, context=context):
result[supplier_info.id] = {} result[supplier_info.id] = {}
address_id = False address_id = False
@@ -73,14 +70,17 @@ class product_supplierinfo(osv.osv):
partner_id = supplier_info.product_id.product_brand_id.partner_id.id partner_id = supplier_info.product_id.product_brand_id.partner_id.id
else: else:
partner_id = supplier_info.company_id.partner_id.id partner_id = supplier_info.company_id.partner_id.id
address_id = address_obj.search(cr, uid, [('partner_id', '=', partner_id), ('type', 'like', 'dedicated_delivery')], context=context) # TODO : Find the partner with a delivery address, child of the partner
if not address_id: # v6.1 code with res.partner.address :
address_id = address_obj.search(cr, uid, [('partner_id','=', partner_id), ('type','like','delivery')], context=context) # address_id = address_obj.search(cr, uid, [('partner_id', '=', partner_id), ('type', 'like', 'dedicated_delivery')], context=context)
if not address_id: # if not address_id:
address_id = address_obj.search(cr, uid, [('partner_id', '=', partner_id), ('type', 'like', 'default')], context=context) # address_id = address_obj.search(cr, uid, [('partner_id','=', partner_id), ('type','like','delivery')], context=context)
if not address_id: # if not address_id:
raise osv.except_osv(_('Error !'), _('No address define for the %s!') % return_partner) # address_id = address_obj.search(cr, uid, [('partner_id', '=', partner_id), ('type', 'like', 'default')], context=context)
result[supplier_info.id] = address_id[0] # if not address_id:
# raise osv.except_osv(_('Error !'), _('No address define for the %s!') % return_partner)
# #result[supplier_info.id] = address_id[0]
result[supplier_info.id] = partner_id
return result return result
_columns = { _columns = {
@@ -88,13 +88,12 @@ class product_supplierinfo(osv.osv):
"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"), "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"),
'return_instructions': fields.many2one('return.instruction', 'Instructions',help="Instructions for product return"), 'return_instructions': fields.many2one('return.instruction', 'Instructions',help="Instructions for product return"),
'active_supplier' : fields.boolean('Active supplier', help=""), 'active_supplier' : fields.boolean('Active supplier', help=""),
'warranty_return_address': fields.function(_get_warranty_return_address, type='many2one', relation='res.partner.address', string="Warranty return address"), 'warranty_return_address': fields.function(_get_warranty_return_address, type='many2one', relation='res.partner', string="Warranty return address"),
} }
_defaults = { _defaults = {
'warranty_return_partner': lambda *a: 'company', 'warranty_return_partner': lambda *a: 'company',
'return_instructions': _get_default_instructions, 'return_instructions': _get_default_instructions,
} }
product_supplierinfo()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: