Merge pull request #52 from gurneyalex/8.0-fix-crm_claim_rma_new_API

fix mistakes made when porting to the new API
This commit is contained in:
Pedro M. Baeza
2015-09-28 17:09:19 +02:00
4 changed files with 32 additions and 31 deletions

View File

@@ -88,6 +88,7 @@ class AccountInvoiceLine(models.Model):
_inherit = "account.invoice.line"
@api.model
@api.returns('self', lambda value: value.id)
def create(self, vals):
claim_line_id = vals.get('claim_line_id')
if claim_line_id:

View File

@@ -72,19 +72,6 @@ class ClaimLine(models.Model):
self.return_value = (self.unit_sale_price *
self.product_returned_quantity)
@api.model
def copy_data(self, default=None):
if default is None:
default = {}
std_default = {
'move_in_id': False,
'move_out_id': False,
'refund_line_id': False,
}
std_default.update(default)
return super(ClaimLine, self).copy_data(default=std_default)
def get_warranty_return_partner(self):
return self.env['product.supplierinfo'].get_warranty_return_partner()
@@ -178,14 +165,17 @@ class ClaimLine(models.Model):
refund_line_id = fields.Many2one(
'account.invoice.line',
string='Refund Line',
copy=False,
help='The refund line related to the returned product')
move_in_id = fields.Many2one(
'stock.move',
string='Move Line from picking in',
copy=False,
help='The move line related to the returned product')
move_out_id = fields.Many2one(
'stock.move',
string='Move Line from picking out',
copy=False,
help='The move line related to the returned product')
location_dest_id = fields.Many2one(
'stock.location',
@@ -420,18 +410,6 @@ class CrmClaim(models.Model):
def name_get(self):
return (self.id, u'[{}] {}'.format(self.code or '', self.name))
@api.model
def copy_data(self, default=None):
if default is None:
default = {}
std_default = {
'invoice_ids': False,
'picking_ids': False,
'code': self.env['ir.sequence'].get('crm.claim'),
}
std_default.update(default)
return super(CrmClaim, self).copy_data(std_default)
claim_line_ids = fields.One2many('claim.line', 'claim_id',
string='Claim lines')
planned_revenue = fields.Float(string='Expected revenue')
@@ -439,8 +417,11 @@ class CrmClaim(models.Model):
real_revenue = fields.Float(string='Real revenue')
real_cost = fields.Float(string='Real cost')
invoice_ids = fields.One2many('account.invoice', 'claim_id',
string='Refunds')
picking_ids = fields.One2many('stock.picking', 'claim_id', string='RMA')
string='Refunds',
copy=False)
picking_ids = fields.One2many('stock.picking', 'claim_id',
string='RMA',
copy=False)
invoice_id = fields.Many2one(
'account.invoice',
string='Invoice',
@@ -513,12 +494,18 @@ class CrmClaim(models.Model):
if self.invoice_id:
self.delivery_address_id = self.invoice_id.partner_id.id
@api.model
@api.multi
def message_get_reply_to(self):
""" Override to get the reply_to of the parent project. """
return [claim.section_id.message_get_reply_to()[0]
if claim.section_id else False
for claim in self.sudo()]
result = {}
for claim in self.sudo():
section = claim.section_id
if section:
section_reply_to = section.message_get_reply_to()
result[claim.id] = section_reply_to[section.id]
else:
result[claim.id] = False
return result
@api.multi
def message_get_suggested_recipients(self):

View File

@@ -31,6 +31,7 @@ class StockPicking(models.Model):
claim_id = fields.Many2one('crm.claim', string='Claim')
@api.model
@api.returns('self', lambda value: value.id)
def create(self, vals):
if ('name' not in vals) or (vals.get('name') == '/'):
vals['name'] = self.env['ir.sequence'].get(self._name)
@@ -41,6 +42,7 @@ class StockMove(models.Model):
_inherit = "stock.move"
@api.model
@api.returns('self', lambda value: value.id)
def create(self, vals):
"""
In case of a wrong picking out, We need to create a new stock_move in a

View File

@@ -142,3 +142,14 @@ class TestPickingCreation(common.TransactionCase):
self.assertEquals(picking.location_dest_id,
self.warehouse_id.lot_stock_id,
"Incorrect destination location")
def test_copy(self):
new_claim = self.claim_id.copy()
self.assertNotEqual(new_claim.code, self.claim_id.code)
def test_mail_thread_recipient(self):
recipients = self.claim_id.message_get_suggested_recipients()
recipients = recipients[self.claim_id.id]
recipient_ids = [r[0] for r in recipients]
self.assertEqual(recipient_ids,
[self.claim_id.partner_id.id])