From 47ff1f58203071cb216d0e788fd39836a94efafc Mon Sep 17 00:00:00 2001 From: Benoit Guillot Date: Wed, 19 Sep 2012 18:25:16 +0200 Subject: [PATCH] [IMP] fix buttons on views and add check if refund and picking is already created for the claim and change the type of the field name on crm_claim --- crm_claim_rma/account_invoice.py | 15 ++++++++++----- crm_claim_rma/crm_claim_rma.py | 14 +++++++++++++- crm_claim_rma/crm_claim_rma_view.xml | 1 - crm_claim_rma/stock_view.xml | 8 ++++++-- crm_claim_rma/wizard/account_invoice_refund.py | 6 +++++- crm_claim_rma/wizard/claim_make_picking.py | 16 ++++++++++++++-- .../wizard/claim_make_picking_from_picking.py | 1 - 7 files changed, 48 insertions(+), 13 deletions(-) diff --git a/crm_claim_rma/account_invoice.py b/crm_claim_rma/account_invoice.py index b78317e6..61408c76 100644 --- a/crm_claim_rma/account_invoice.py +++ b/crm_claim_rma/account_invoice.py @@ -22,6 +22,7 @@ ######################################################################### from osv import fields, osv +from tools.translate import _ class account_invoice(osv.osv): @@ -42,11 +43,15 @@ class account_invoice(osv.osv): new_lines = [] if context.get('claim_line_ids') and lines and 'product_id' in lines[0]:#check if is an invoice_line for claim_line_id in context.get('claim_line_ids'): - claim_info = self.pool.get('claim.line').read(cr, uid, claim_line_id[1], ['invoice_line_id', 'product_returned_quantity'], context=context) - invoice_line_info = self.pool.get('account.invoice.line').read(cr, uid, claim_info['invoice_line_id'][0], context=context) - invoice_line_info['quantity'] = claim_info['product_returned_quantity'] - invoice_line_info['claim_line_id'] = claim_line_id - new_lines.append(invoice_line_info) + claim_info = self.pool.get('claim.line').read(cr, uid, claim_line_id[1], ['invoice_line_id', 'product_returned_quantity', 'refund_line_id'], context=context) + if not claim_info['refund_line_id']: + invoice_line_info = self.pool.get('account.invoice.line').read(cr, uid, claim_info['invoice_line_id'][0], context=context) + invoice_line_info['quantity'] = claim_info['product_returned_quantity'] + invoice_line_info['claim_line_id'] = [claim_line_id[1]] + new_lines.append(invoice_line_info) + if not new_lines: + #TODO use custom states to show button of this wizard or not instead of raise an error + raise osv.except_osv(_('Error !'), _('A refund has already been created for this claim !')) lines = new_lines result = super(account_invoice, self)._refund_cleanup_lines(cr, uid, lines, context=context) return result diff --git a/crm_claim_rma/crm_claim_rma.py b/crm_claim_rma/crm_claim_rma.py index 90fa9118..808a961d 100644 --- a/crm_claim_rma/crm_claim_rma.py +++ b/crm_claim_rma/crm_claim_rma.py @@ -269,7 +269,7 @@ class crm_claim(osv.osv): 'picking_ids': fields.one2many('stock.picking', 'claim_id', 'RMA'), 'invoice_id': fields.many2one('account.invoice', 'Invoice', help='Related invoice'), 'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse', required=True), - 'case_id': fields.many2one('claim.rma.case', 'Case'), + 'name': fields.many2one('claim.rma.case', 'Claim Subject', size=128, required=True), } _defaults = { 'number': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'crm.claim'), @@ -300,6 +300,18 @@ class crm_claim(osv.osv): # 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) + if add: + if not res['value']['email_from'] or not res['value']['partner_phone']: + address = self.pool.get('res.partner.address').browse(cr, uid, add) + for other_add in address.partner_id.address: + if other_add.email and not res['value']['email_from']: + res['value']['email_from'] = other_add.email + if other_add.phone and not res['value']['partner_phone']: + res['value']['partner_phone'] = other_add.phone + return res + def onchange_invoice_id(self, cr, uid, ids, invoice_id, context=None): invoice_line_obj = self.pool.get('account.invoice.line') invoice_line_ids = invoice_line_obj.search(cr, uid, [('invoice_id', '=', invoice_id)]) diff --git a/crm_claim_rma/crm_claim_rma_view.xml b/crm_claim_rma/crm_claim_rma_view.xml index 59d57404..52a5ea50 100644 --- a/crm_claim_rma/crm_claim_rma_view.xml +++ b/crm_claim_rma/crm_claim_rma_view.xml @@ -268,7 +268,6 @@ - diff --git a/crm_claim_rma/stock_view.xml b/crm_claim_rma/stock_view.xml index 5ab7069e..a06f348c 100644 --- a/crm_claim_rma/stock_view.xml +++ b/crm_claim_rma/stock_view.xml @@ -21,9 +21,9 @@ + - {'invisible':['|', ('state','<>','done'), ('claim_picking', '!=', False)]} - + 1 + + + 1 + diff --git a/crm_claim_rma/wizard/account_invoice_refund.py b/crm_claim_rma/wizard/account_invoice_refund.py index 13619195..f764ab48 100644 --- a/crm_claim_rma/wizard/account_invoice_refund.py +++ b/crm_claim_rma/wizard/account_invoice_refund.py @@ -31,7 +31,11 @@ class account_invoice_refund(osv.osv_memory): def _get_description(self, cr, uid, context=None): if context is None: context = {} - return context.get('description', '') + if context.get('description'): + description = self.pool.get('claim.rma.case').read(cr, uid, context.get('description'), ['name'], context=context)['name'] + else: + description = '' + return description _defaults = { 'description': _get_description, diff --git a/crm_claim_rma/wizard/claim_make_picking.py b/crm_claim_rma/wizard/claim_make_picking.py index fdc3fe6b..7007b3f9 100644 --- a/crm_claim_rma/wizard/claim_make_picking.py +++ b/crm_claim_rma/wizard/claim_make_picking.py @@ -25,6 +25,7 @@ from osv import fields, osv import time from tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT import netsvc +from tools.translate import _ class claim_make_picking(osv.osv_memory): @@ -37,7 +38,16 @@ class claim_make_picking(osv.osv_memory): } def _get_claim_lines(self, cr, uid, context): - return self.pool.get('crm.claim').read(cr, uid, context['active_id'], ['claim_line_ids'], context=context)['claim_line_ids'] + #TODO use custom states to show buttons of this wizard or not instead of raise an error + if context is None: context = {} + if context.get('picking_type') in ['in', 'loss']: + move_field = 'move_in_id' + elif context.get('picking_type') == 'out': + move_field = 'move_out_id' + line_ids = self.pool.get('claim.line').search(cr, uid, [('claim_id', '=', context['active_id']), (move_field, '=', False)], context=context) + if not line_ids: + raise osv.except_osv(_('Error !'), _('A picking has already been created for this claim !')) + return line_ids # Get default source location def _get_source_loc(self, cr, uid, context): @@ -79,12 +89,14 @@ class claim_make_picking(osv.osv_memory): picking_obj = self.pool.get('stock.picking') if context is None: context = {} view_obj = self.pool.get('ir.ui.view') + claim_picking = False if context.get('picking_type') in ['in', 'loss']: 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': + claim_picking = True note = 'RMA picking in' name = 'Customer picking in' elif context.get('picking_type') == 'loss': @@ -120,7 +132,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 + 'claim_picking': claim_picking }) # Create picking lines for wizard_claim_line in wizard.claim_line_ids: diff --git a/crm_claim_rma/wizard/claim_make_picking_from_picking.py b/crm_claim_rma/wizard/claim_make_picking_from_picking.py index 27897846..7951d96c 100644 --- a/crm_claim_rma/wizard/claim_make_picking_from_picking.py +++ b/crm_claim_rma/wizard/claim_make_picking_from_picking.py @@ -100,7 +100,6 @@ class claim_make_picking_from_picking(osv.osv_memory): '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: