From 09e8a8d132f8bbc3858b75f99ec21a61a05e0b9f Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 28 Sep 2015 15:32:18 +0200 Subject: [PATCH 1/2] fix mistakes made when porting to the new API --- crm_claim_rma/models/account_invoice.py | 1 + crm_claim_rma/models/crm_claim_rma.py | 18 ++++++++++++------ crm_claim_rma/models/stock.py | 2 ++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/crm_claim_rma/models/account_invoice.py b/crm_claim_rma/models/account_invoice.py index 8b000cd3..012a0e61 100644 --- a/crm_claim_rma/models/account_invoice.py +++ b/crm_claim_rma/models/account_invoice.py @@ -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: diff --git a/crm_claim_rma/models/crm_claim_rma.py b/crm_claim_rma/models/crm_claim_rma.py index 3a7f90a0..812a06dc 100644 --- a/crm_claim_rma/models/crm_claim_rma.py +++ b/crm_claim_rma/models/crm_claim_rma.py @@ -72,7 +72,7 @@ class ClaimLine(models.Model): self.return_value = (self.unit_sale_price * self.product_returned_quantity) - @api.model + @api.multi def copy_data(self, default=None): if default is None: default = {} @@ -420,7 +420,7 @@ class CrmClaim(models.Model): def name_get(self): return (self.id, u'[{}] {}'.format(self.code or '', self.name)) - @api.model + @api.multi def copy_data(self, default=None): if default is None: default = {} @@ -513,12 +513,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): diff --git a/crm_claim_rma/models/stock.py b/crm_claim_rma/models/stock.py index 282013b4..616199bb 100644 --- a/crm_claim_rma/models/stock.py +++ b/crm_claim_rma/models/stock.py @@ -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 From 9cb4451f6f2a923a955b4f52adade0eb0cfb015c Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 28 Sep 2015 15:47:14 +0200 Subject: [PATCH 2/2] replace copy_data override with copy=False the code for code is already in copy_data of crm_claim_code. added test --- crm_claim_rma/models/crm_claim_rma.py | 35 +++++--------------- crm_claim_rma/tests/test_picking_creation.py | 11 ++++++ 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/crm_claim_rma/models/crm_claim_rma.py b/crm_claim_rma/models/crm_claim_rma.py index 812a06dc..cc8bed76 100644 --- a/crm_claim_rma/models/crm_claim_rma.py +++ b/crm_claim_rma/models/crm_claim_rma.py @@ -72,19 +72,6 @@ class ClaimLine(models.Model): self.return_value = (self.unit_sale_price * self.product_returned_quantity) - @api.multi - 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.multi - 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', diff --git a/crm_claim_rma/tests/test_picking_creation.py b/crm_claim_rma/tests/test_picking_creation.py index ce09c56e..fecdc1c4 100644 --- a/crm_claim_rma/tests/test_picking_creation.py +++ b/crm_claim_rma/tests/test_picking_creation.py @@ -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])