From cc9d0f0a97bde077bc043a0b3a049896200d0378 Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Thu, 23 Jan 2020 11:37:38 +0100 Subject: [PATCH] [ENH]rma_sale traceability --- rma/views/res_partner_view.xml | 2 +- rma_account/views/invoice_view.xml | 4 +- rma_sale/__manifest__.py | 2 +- rma_sale/models/__init__.py | 1 + rma_sale/models/sale_order.py | 38 +++++++++++++++++++ rma_sale/views/sale_order_view.xml | 23 +++++++++++ .../wizards/rma_order_line_make_sale_order.py | 33 +++++++++++----- .../rma_order_line_make_sale_order_view.xml | 5 ++- 8 files changed, 92 insertions(+), 16 deletions(-) create mode 100644 rma_sale/models/sale_order.py diff --git a/rma/views/res_partner_view.xml b/rma/views/res_partner_view.xml index 19b34670..64f1f403 100755 --- a/rma/views/res_partner_view.xml +++ b/rma/views/res_partner_view.xml @@ -10,7 +10,7 @@ + + + + + diff --git a/rma_sale/wizards/rma_order_line_make_sale_order.py b/rma_sale/wizards/rma_order_line_make_sale_order.py index 0cba6c9f..54ad5bf7 100644 --- a/rma_sale/wizards/rma_order_line_make_sale_order.py +++ b/rma_sale/wizards/rma_order_line_make_sale_order.py @@ -14,7 +14,7 @@ class RmaLineMakeSaleOrder(models.TransientModel): domain=[('customer', '=', True)]) item_ids = fields.One2many( comodel_name='rma.order.line.make.sale.order.item', - inverse_name='wiz_id', string='Items') + inverse_name='wiz_id', string='Items', readonly=False) sale_order_id = fields.Many2one( comodel_name='sale.order', string='Sales Order', required=False, domain=[('state', '=', 'draft')]) @@ -58,16 +58,16 @@ class RmaLineMakeSaleOrder(models.TransientModel): return res @api.model - def _prepare_sale_order(self, out_warehouse, company, item): + def _prepare_sale_order(self, line): if not self.partner_id: raise exceptions.Warning( _('Enter a customer.')) customer = self.partner_id data = { - 'origin': item.line_id.name, + 'origin': line.name, 'partner_id': customer.id, - 'warehouse_id': out_warehouse.id, - 'company_id': company.id, + 'warehouse_id': line.out_warehouse_id.id, + 'company_id': line.company_id.id, } return data @@ -102,11 +102,9 @@ class RmaLineMakeSaleOrder(models.TransientModel): if self.sale_order_id: sale = self.sale_order_id if not sale: - po_data = self._prepare_sale_order( - line.out_warehouse_id, - line.company_id, - item) + po_data = self._prepare_sale_order(line) sale = sale_obj.create(po_data) + sale.name = sale.name + ' - ' + line.name so_line_data = self._prepare_sale_order_line(sale, item) so_line_obj.create(so_line_data) @@ -125,7 +123,8 @@ class RmaLineMakeSaleOrderItem(models.TransientModel): wiz_id = fields.Many2one( comodel_name='rma.order.line.make.sale.order', string='Wizard') line_id = fields.Many2one( - comodel_name='rma.order.line', string='RMA Line') + comodel_name='rma.order.line', string='RMA Line', + compute='compute_line_id') rma_id = fields.Many2one( comodel_name='rma.order', related='line_id.rma_id', readonly=False) product_id = fields.Many2one( @@ -138,3 +137,17 @@ class RmaLineMakeSaleOrderItem(models.TransientModel): out_warehouse_id = fields.Many2one( comodel_name='stock.warehouse', string='Outbound Warehouse') free_of_charge = fields.Boolean(string='Free of Charge') + + def compute_line_id(self): + rma_line_obj = self.env['rma.order.line'] + for rec in self: + if not self.env.context['active_ids']: + return + rma_line_ids = self.env.context['active_ids'] or [] + lines = rma_line_obj.browse(rma_line_ids) + rec.line_id = lines[0] + + @api.onchange('product_id') + def onchange_product_id(self): + if self.product_id: + self.name = self.product_id.name diff --git a/rma_sale/wizards/rma_order_line_make_sale_order_view.xml b/rma_sale/wizards/rma_order_line_make_sale_order_view.xml index 78052ca1..31bcd69c 100644 --- a/rma_sale/wizards/rma_order_line_make_sale_order_view.xml +++ b/rma_sale/wizards/rma_order_line_make_sale_order_view.xml @@ -26,9 +26,10 @@ - + + + invisible="True"/>