[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

This commit is contained in:
Benoit Guillot
2012-09-19 18:25:16 +02:00
parent 8f4f7a5710
commit 47ff1f5820
7 changed files with 48 additions and 13 deletions

View File

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

View File

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

View File

@@ -268,7 +268,6 @@
<field name="date_deadline" position="after">
<field name="number"/>
<field name="claim_type"/>
<field name="case_id" />
<field name="warehouse_id" />
</field>
</field>

View File

@@ -21,9 +21,9 @@
<field name="claim_id" />
<field name="claim_picking" invisible="1"/>
</xpath>
<!-- If we use crm_claim_rma we should not use the old return products anymore-->
<xpath expr="/form/notebook/page[@string='General Information']/group/button[@string='Return Products']" position="attributes">
<attribute name="attrs">{'invisible':['|', ('state','&lt;&gt;','done'), ('claim_picking', '!=', False)]}</attribute>
<attribute name="states"></attribute>
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="/form/notebook/page[@string='General Information']/group/button[@string='Return Products']" position="after">
<group name="claim_picking_button" attrs="{'invisible':['|',
@@ -52,6 +52,10 @@
<xpath expr="/form/notebook/page[@string='Additional info']/field[@name='type']" position="after">
<field name="claim_id" />
</xpath>
<!-- If we use crm_claim_rma we should not use the old return products anymore-->
<xpath expr="/form/notebook/page[@string='Products']/group/button[@string='Return Products']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
</data>
</field>
</record>

View File

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

View File

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

View File

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