From 548e2b6e0a4ba6de2f38734d0d4e056db768b3cd Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Mon, 14 May 2018 14:58:42 +0200 Subject: [PATCH] [9.0] rma: * proper link between customer and supplier rma. * fix wizard for generating supplier rma. * several view issues. --- rma/models/rma_order_line.py | 44 ++++++++- rma/views/rma_order_line_view.xml | 91 ++++++++++++------- rma/wizards/rma_make_picking.py | 2 + .../rma_order_line_make_supplier_rma.py | 5 +- 4 files changed, 103 insertions(+), 39 deletions(-) diff --git a/rma/models/rma_order_line.py b/rma/models/rma_order_line.py index 3802625a..b0c93e4d 100644 --- a/rma/models/rma_order_line.py +++ b/rma/models/rma_order_line.py @@ -158,6 +158,13 @@ class RmaOrderLine(models.Model): rec.procurement_count = len(rec.procurement_ids.filtered( lambda p: p.state == 'exception')) + @api.multi + def _compute_rma_line_count(self): + for rec in self.filtered(lambda r: r.type == 'customer'): + rec.rma_line_count = len(rec.supplier_rma_line_ids) + for rec in self.filtered(lambda r: r.type == 'supplier'): + rec.rma_line_count = len(rec.customer_rma_id) + delivery_address_id = fields.Many2one( comodel_name='res.partner', string='Partner delivery address', default=_default_delivery_address, @@ -313,11 +320,21 @@ class RmaOrderLine(models.Model): 'rma.order.line', string='Customer RMA line', ondelete='cascade') supplier_rma_line_ids = fields.One2many( 'rma.order.line', 'customer_rma_id') + rma_line_count = fields.Integer( + compute='_compute_rma_line_count', + string='# of RMA lines associated', + ) supplier_address_id = fields.Many2one( - 'res.partner', readonly=True, + comodel_name='res.partner', readonly=True, states={'draft': [('readonly', False)]}, string='Supplier Address', - help="This address of the supplier in case of Customer RMA operation " + help="Address of the supplier in case of Customer RMA operation " + "dropship.") + customer_address_id = fields.Many2one( + comodel_name='res.partner', readonly=True, + states={'draft': [('readonly', False)]}, + string='Customer Address', + help="Address of the customer in case of Supplier RMA operation " "dropship.") qty_to_receive = fields.Float( string='Qty To Receive', @@ -602,3 +619,26 @@ class RmaOrderLine(models.Model): result['views'] = [(res and res.id or False, 'form')] result['res_id'] = procurements[0] return result + + @api.multi + def action_view_rma_lines(self): + if self.type == 'customer': + # from customer we link to supplier rma + action = self.env.ref( + 'rma.action_rma_supplier_lines') + rma_lines = self.supplier_rma_line_ids.ids + res = self.env.ref('rma.view_rma_line_supplier_form', False) + else: + # from supplier we link to customer rma + action = self.env.ref( + 'rma.action_rma_customer_lines') + rma_lines = self.customer_rma_id.ids + res = self.env.ref('rma.view_rma_line_form', False) + result = action.read()[0] + # choose the view_mode accordingly + if len(rma_lines) != 1: + result['domain'] = rma_lines.ids + elif len(rma_lines) == 1: + result['views'] = [(res and res.id or False, 'form')] + result['res_id'] = rma_lines[0] + return result diff --git a/rma/views/rma_order_line_view.xml b/rma/views/rma_order_line_view.xml index 4fdc9328..7cbc254a 100644 --- a/rma/views/rma_order_line_view.xml +++ b/rma/views/rma_order_line_view.xml @@ -90,6 +90,13 @@ +

@@ -136,23 +143,28 @@ - + + + + - - - - - - - - - - - - + + + + + + + + + + + + @@ -200,7 +212,7 @@ rma.order.line.form rma.order.line -
+
+

@@ -298,13 +317,13 @@ - + - + - + - + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/rma/wizards/rma_make_picking.py b/rma/wizards/rma_make_picking.py index e70cd751..dd7c8b8c 100644 --- a/rma/wizards/rma_make_picking.py +++ b/rma/wizards/rma_make_picking.py @@ -81,6 +81,8 @@ class RmaMakePicking(models.TransientModel): def _get_address(self, item): if item.line_id.customer_to_supplier: delivery_address = item.line_id.supplier_address_id + elif item.line_id.supplier_to_customer: + delivery_address = item.line_id.customer_address_id elif item.line_id.delivery_address_id: delivery_address = item.line_id.delivery_address_id elif item.line_id.partner_id: diff --git a/rma/wizards/rma_order_line_make_supplier_rma.py b/rma/wizards/rma_order_line_make_supplier_rma.py index d5a12b68..183da051 100644 --- a/rma/wizards/rma_order_line_make_supplier_rma.py +++ b/rma/wizards/rma_order_line_make_supplier_rma.py @@ -108,8 +108,9 @@ class RmaLineMakeSupplierRma(models.TransientModel): 'partner_id': self.partner_id.id, 'type': 'supplier', 'origin': item.line_id.rma_id.name, - 'delivery_address_id': - item.line_id.delivery_address_id.id, + 'customer_address_id': + item.line_id.delivery_address_id.id or + item.line_id.partner_id.id, 'product_id': item.line_id.product_id.id, 'customer_rma_id': item.line_id.id, 'product_qty': item.product_qty,