From 56dee1e9b3d7344009d774bc12398301a517dd22 Mon Sep 17 00:00:00 2001 From: lreficent Date: Fri, 25 Aug 2017 12:22:53 +0200 Subject: [PATCH] [9.0][IMP] rma_account: * remove unneded copy attributes. * simplify action_view methods. * fix wrong naming. * fix misplaced views. * fix wrong count and view actions for rma.orders in invoices. * fix error when installing the module. * remove unneded data update when preparing rma lines from invoice lines. * minor extra fixes. --- rma_account/README.rst | 13 +++--- rma_account/__openerp__.py | 15 +++---- rma_account/models/invoice.py | 46 +++++++-------------- rma_account/models/rma_order.py | 47 ++++++---------------- rma_account/models/rma_order_line.py | 16 +++----- rma_account/views/invoice_view.xml | 8 ++-- rma_account/views/rma_order_view.xml | 4 +- rma_account/wizards/rma_add_invoice.py | 53 ++++++++++++------------- rma_account/wizards/rma_add_invoice.xml | 6 +-- rma_account/wizards/rma_refund.py | 11 +++-- 10 files changed, 86 insertions(+), 133 deletions(-) diff --git a/rma_account/README.rst b/rma_account/README.rst index eadfe985..56f20fd3 100644 --- a/rma_account/README.rst +++ b/rma_account/README.rst @@ -6,18 +6,19 @@ RMA Account =========== This module integrates Return Merchandise Authorizations (RMA) with invoices, - allowing to: +allowing to: #. Create complete RMA's using existing invoices as a reference. -#. Create refunds from RMA. +#. Create refunds from a RMA. Usage ===== -RMA are accessible though Inventory menu. There's four menus, divided by type -. Users can access to the list of RMA or RMA lines. +RMA are accessible though Inventory menu. There's four menus, divided by type. +Users can access to the list of RMA or RMA lines. Create an RMA: + #. Select a partner. Fill the rma lines by selecting an invoice. #. Request approval and approve. #. Click on RMA Lines button. @@ -25,7 +26,6 @@ Create an RMA: Order, Create Refund". #. Go back to the RMA. Set the RMA to done if not further action is required. - Bug Tracker =========== @@ -34,7 +34,6 @@ Bugs are tracked on `GitHub Issues check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed feedback. - Credits ======= @@ -43,7 +42,7 @@ Contributors * Jordi Ballester Alomar * Aaron Henriquez - +* Lois Rilo Maintainer ---------- diff --git a/rma_account/__openerp__.py b/rma_account/__openerp__.py index 43522ee7..07696111 100644 --- a/rma_account/__openerp__.py +++ b/rma_account/__openerp__.py @@ -12,13 +12,14 @@ 'website': 'http://www.github.com/OCA/rma', 'depends': ['account', 'rma'], 'demo': ['demo/rma_operation.xml'], - 'data': ['views/rma_order_view.xml', - 'views/rma_operation_view.xml', - 'views/rma_order_line_view.xml', - 'views/invoice_view.xml', - 'wizards/rma_add_invoice.xml', - 'wizards/rma_refund.xml', - ], + 'data': [ + 'views/rma_order_view.xml', + 'views/rma_operation_view.xml', + 'views/rma_order_line_view.xml', + 'views/invoice_view.xml', + 'wizards/rma_add_invoice.xml', + 'wizards/rma_refund.xml', + ], 'installable': True, 'auto_install': True, } diff --git a/rma_account/models/invoice.py b/rma_account/models/invoice.py index 9f33a501..55dc4f26 100644 --- a/rma_account/models/invoice.py +++ b/rma_account/models/invoice.py @@ -6,34 +6,25 @@ from openerp import api, fields, models class AccountInvoice(models.Model): - _inherit = "account.invoice" @api.one def _compute_rma_count(self): - rma_list = [] - for invl in self.invoice_line_ids: - for rmal in invl.rma_line_ids: - rma_list.append(rmal.rma_id.id) - self.rma_count = len(list(set(rma_list))) + for inv in self: + rmas = self.mapped('invoice_line_ids.rma_line_ids.rma_id') + inv.rma_count = len(rmas) - rma_count = fields.Integer(compute=_compute_rma_count, - string='# of RMA', - copy=False) + rma_count = fields.Integer( + compute=_compute_rma_count, string='# of RMA') @api.multi def action_view_rma_supplier(self): action = self.env.ref('rma.action_rma_supplier') result = action.read()[0] - rma_list = [] - for invl in self.invoice_line_ids: - for rmal in invl.rma_line_ids: - rma_list.append(rmal.rma_id.id) - self.rma_count = len(list(set(rma_list))) + rma_list = self.mapped('invoice_line_ids.rma_line_ids.rma_id').ids # choose the view_mode accordingly if len(rma_list) != 1: - result['domain'] = "[('id', 'in', " + \ - str(rma_list) + ")]" + result['domain'] = [('id', 'in', rma_list)] elif len(rma_list) == 1: res = self.env.ref('rma.view_rma_supplier_form', False) result['views'] = [(res and res.id or False, 'form')] @@ -41,18 +32,13 @@ class AccountInvoice(models.Model): return result @api.multi - def action_view_rma(self): + def action_view_rma_customer(self): action = self.env.ref('rma.action_rma_customer') result = action.read()[0] - rma_list = [] - for invl in self.invoice_line_ids: - for rmal in invl.rma_line_ids: - rma_list.append(rmal.rma_id.id) - self.rma_count = len(list(set(rma_list))) + rma_list = self.mapped('invoice_line_ids.rma_line_ids.rma_id').ids # choose the view_mode accordingly if len(rma_list) != 1: - result['domain'] = "[('id', 'in', " + \ - str(rma_list) + ")]" + result['domain'] = [('id', 'in', rma_list)] elif len(rma_list) == 1: res = self.env.ref('rma.view_rma_form', False) result['views'] = [(res and res.id or False, 'form')] @@ -61,20 +47,16 @@ class AccountInvoice(models.Model): class AccountInvoiceLine(models.Model): - _inherit = "account.invoice.line" @api.multi def _compute_rma_count(self): - rma_list = [] for invl in self: - for rmal in invl.rma_line_ids: - rma_list.append(rmal.rma_id.id) - invl.rma_count = len(list(set(rma_list))) + rma_lines = invl.mapped('rma_line_ids') + invl.rma_line_count = len(rma_lines) - rma_count = fields.Integer(compute=_compute_rma_count, - string='# of RMA', - copy=False) + rma_line_count = fields.Integer( + compute=_compute_rma_count, string='# of RMA') rma_line_ids = fields.One2many( comodel_name='rma.order.line', inverse_name='invoice_line_id', string="RMA", readonly=True, diff --git a/rma_account/models/rma_order.py b/rma_account/models/rma_order.py index ff751945..4f6c6868 100644 --- a/rma_account/models/rma_order.py +++ b/rma_account/models/rma_order.py @@ -10,31 +10,23 @@ class RmaOrder(models.Model): @api.multi def _compute_invoice_refund_count(self): for rec in self: - invoice_list = [] - for line in rec.rma_line_ids: - for refund in line.refund_line_ids: - invoice_list.append(refund.invoice_id.id) - rec.invoice_refund_count = len(list(set(invoice_list))) + invoices = rec.mapped( + 'rma_line_ids.refund_line_ids.invoice_id') + rec.invoice_refund_count = len(invoices) @api.multi def _compute_invoice_count(self): for rec in self: - invoice_list = [] - for line in rec.rma_line_ids: - if line.invoice_line_id and line.invoice_line_id.id: - invoice_list.append(line.invoice_line_id.invoice_id.id) - rec.invoice_count = len(list(set(invoice_list))) + invoices = rec.mapped('rma_line_ids.invoice_id') + rec.invoice_count = len(invoices) add_invoice_id = fields.Many2one('account.invoice', string='Add Invoice', ondelete='set null', readonly=True, states={'draft': [('readonly', False)]}) invoice_refund_count = fields.Integer( - compute=_compute_invoice_refund_count, - string='# of Refunds', - copy=False) - invoice_count = fields.Integer(compute=_compute_invoice_count, - string='# of Incoming Shipments', - copy=False) + compute=_compute_invoice_refund_count, string='# of Refunds') + invoice_count = fields.Integer( + compute=_compute_invoice_count, string='# of Invoices') def _prepare_rma_line_from_inv_line(self, line): if self.type == 'customer': @@ -94,22 +86,13 @@ class RmaOrder(models.Model): @api.multi def action_view_invoice_refund(self): - """ - This function returns an action that display existing vendor refund - bills of given purchase order id. - When only one found, show the vendor bill immediately. - """ action = self.env.ref('account.action_invoice_tree2') result = action.read()[0] - invoice_list = [] - for line in self.rma_line_ids: - for refund in line.refund_line_ids: - invoice_list.append(refund.invoice_id.id) - invoice_ids = list(set(invoice_list)) + invoice_ids = self.mapped( + 'rma_line_ids.refund_line_ids.invoice_id').ids # choose the view_mode accordingly if len(invoice_ids) != 1: - result['domain'] = "[('id', 'in', " + \ - str(invoice_ids) + ")]" + result['domain'] = [('id', 'in', invoice_ids)] elif len(invoice_ids) == 1: res = self.env.ref('account.invoice_supplier_form', False) result['views'] = [(res and res.id or False, 'form')] @@ -123,14 +106,10 @@ class RmaOrder(models.Model): else: action = self.env.ref('account.action_invoice_tree') result = action.read()[0] - invoice_list = [] - for line in self.rma_line_ids: - invoice_list.append(line.invoice_id.id) - invoice_ids = list(set(invoice_list)) + invoice_ids = self.mapped('rma_line_ids.invoice_id').ids # choose the view_mode accordingly if len(invoice_ids) != 1: - result['domain'] = "[('id', 'in', " + \ - str(invoice_ids) + ")]" + result['domain'] = [('id', 'in', invoice_ids)] elif len(invoice_ids) == 1: if self.type == "supplier": res = self.env.ref('account.invoice_supplier_form', False) diff --git a/rma_account/models/rma_order_line.py b/rma_account/models/rma_order_line.py index 9f396edd..30adcb04 100644 --- a/rma_account/models/rma_order_line.py +++ b/rma_account/models/rma_order_line.py @@ -11,10 +11,10 @@ class RmaOrderLine(models.Model): @api.model def _default_invoice_address(self): - partner_id = self.env.context.get('partner_id', False) + partner_id = self.env.context.get('partner_id') if partner_id: return self.env['res.partner'].browse(partner_id) - return False + return self.env['res.partner'] @api.multi @api.depends('refund_line_ids', 'refund_line_ids.invoice_id.state', @@ -46,9 +46,8 @@ class RmaOrderLine(models.Model): default=_default_invoice_address, help="Invoice address for current rma order.") - refund_count = fields.Integer(compute=_compute_refund_count, - string='# of Refunds', copy=False, default=0) - + refund_count = fields.Integer( + compute=_compute_refund_count, string='# of Refunds', default=0) invoice_line_id = fields.Many2one('account.invoice.line', string='Invoice Line', ondelete='restrict', @@ -118,13 +117,10 @@ class RmaOrderLine(models.Model): def action_view_refunds(self): action = self.env.ref('account.action_invoice_tree2') result = action.read()[0] - invoice_ids = [] - for inv_line in self.refund_line_ids: - invoice_ids.append(inv_line.invoice_id.id) + invoice_ids= self.mapped('refund_line_ids.invoice_id').ids # choose the view_mode accordingly if len(invoice_ids) != 1: - result['domain'] = "[('id', 'in', " + \ - str(invoice_ids) + ")]" + result['domain'] = [('id', 'in', invoice_ids)] elif len(invoice_ids) == 1: res = self.env.ref('account.invoice_supplier_form', False) result['views'] = [(res and res.id or False, 'form')] diff --git a/rma_account/views/invoice_view.xml b/rma_account/views/invoice_view.xml index 647c5043..c1097905 100644 --- a/rma_account/views/invoice_view.xml +++ b/rma_account/views/invoice_view.xml @@ -9,7 +9,7 @@
-