From 55659b3cb3fed6d717365fa3675c65af6cc180aa Mon Sep 17 00:00:00 2001 From: lreficent Date: Thu, 9 Nov 2017 17:48:55 +0100 Subject: [PATCH] [9.0][FIX] rma: create supplier rma wizard --- .../rma_order_line_make_supplier_rma.py | 76 +++++++++---------- .../rma_order_line_make_supplier_rma_view.xml | 6 +- 2 files changed, 40 insertions(+), 42 deletions(-) diff --git a/rma/wizards/rma_order_line_make_supplier_rma.py b/rma/wizards/rma_order_line_make_supplier_rma.py index 59ae981e..79723b01 100644 --- a/rma/wizards/rma_order_line_make_supplier_rma.py +++ b/rma/wizards/rma_order_line_make_supplier_rma.py @@ -3,7 +3,7 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) import openerp.addons.decimal_precision as dp -from openerp import _, api, exceptions, fields, models +from openerp import _, api, fields, models from openerp.exceptions import ValidationError @@ -11,16 +11,17 @@ class RmaLineMakeSupplierRma(models.TransientModel): _name = "rma.order.line.make.supplier.rma" _description = "RMA Line Make Supplier RMA" - partner_id = fields.Many2one('res.partner', string='Supplier', - required=False, - domain=[('supplier', '=', True)]) + partner_id = fields.Many2one( + comodel_name='res.partner', string='Supplier', + domain=[('supplier', '=', True)], required=True, + ) item_ids = fields.One2many( - 'rma.order.line.make.supplier.rma.item', - 'wiz_id', string='Items') - supplier_rma_id = fields.Many2one('rma.order', - string='Supplier RMA Order', - required=False, - domain=[('state', '=', 'draft')]) + comodel_name='rma.order.line.make.supplier.rma.item', + inverse_name='wiz_id', string='Items', + ) + supplier_rma_id = fields.Many2one( + comodel_name='rma.order', string='Supplier RMA Order Group', + ) @api.model def _prepare_item(self, line): @@ -50,12 +51,11 @@ class RmaLineMakeSupplierRma(models.TransientModel): items.append([0, 0, self._prepare_item(line)]) suppliers = lines.mapped('supplier_address_id') if len(suppliers) == 0: - raise exceptions.Warning( - _('Please specify a supplier address')) + pass elif len(suppliers) == 1: res['partner_id'] = suppliers.id else: - raise exceptions.Warning( + raise ValidationError( _('Only RMA lines from the same supplier address can be ' 'processed at the same time')) res['item_ids'] = items @@ -64,8 +64,7 @@ class RmaLineMakeSupplierRma(models.TransientModel): @api.model def _prepare_supplier_rma(self, company): if not self.partner_id: - raise exceptions.Warning( - _('Enter a supplier.')) + raise ValidationError(_('Enter a supplier.')) return { 'partner_id': self.partner_id.id, 'delivery_address_id': self.partner_id.id, @@ -77,7 +76,20 @@ class RmaLineMakeSupplierRma(models.TransientModel): def _prepare_supplier_rma_line(self, rma, item): operation = self.env['rma.operation'].search( [('type', '=', 'supplier')], limit=1) + if not operation.in_route_id or not operation.out_route_id: + route = self.env['stock.location.route'].search( + [('rma_selectable', '=', True)], limit=1) + if not route: + raise ValidationError(_("Please define an RMA route")) + if not operation.in_warehouse_id or not operation.out_warehouse_id: + warehouse = self.env['stock.warehouse'].search( + [('company_id', '=', self.rma_id.company_id.id), + ('lot_rma_id', '!=', False)], limit=1) + if not warehouse: + raise ValidationError( + _("Please define a warehouse with a default RMA location")) data = { + 'partner_id': self.partner_id.id, 'type': 'supplier', 'origin': item.line_id.rma_id.name, 'delivery_address_id': @@ -91,28 +103,14 @@ class RmaLineMakeSupplierRma(models.TransientModel): 'receipt_policy': operation.receipt_policy, 'delivery_policy': operation.delivery_policy, 'supplier_to_customer': operation.supplier_to_customer, - } - if not operation.in_route_id or not operation.out_route_id: - route = self.env['stock.location.route'].search( - [('rma_selectable', '=', True)], limit=1) - if not route: - raise ValidationError(_("Please define an rma route")) - if not operation.in_warehouse_id or not operation.out_warehouse_id: - warehouse = self.env['stock.warehouse'].search( - [('company_id', '=', self.rma_id.company_id.id), - ('lot_rma_id', '!=', False)], limit=1) - if not warehouse: - raise ValidationError(_("Please define a warehouse with a" - " default rma location")) - data.update( - {'in_warehouse_id': operation.in_warehouse_id.id or warehouse.id, - 'out_warehouse_id': operation.out_warehouse_id.id or warehouse.id, - 'in_route_id': operation.in_route_id.id or route.id, - 'out_route_id': operation.out_route_id.id or route.id, - 'location_id': (operation.location_id.id or - operation.in_warehouse_id.lot_rma_id.id or - warehouse.lot_rma_id.id) - }) + 'in_warehouse_id': operation.in_warehouse_id.id or warehouse.id, + 'out_warehouse_id': operation.out_warehouse_id.id or warehouse.id, + 'in_route_id': operation.in_route_id.id or route.id, + 'out_route_id': operation.out_route_id.id or route.id, + 'location_id': (operation.location_id.id or + operation.in_warehouse_id.lot_rma_id.id or + warehouse.lot_rma_id.id) + } return data @api.multi @@ -125,7 +123,7 @@ class RmaLineMakeSupplierRma(models.TransientModel): for item in self.item_ids: line = item.line_id if item.product_qty <= 0.0: - raise exceptions.Warning( + raise ValidationError( _('Enter a positive quantity.')) if self.supplier_rma_id: @@ -167,5 +165,5 @@ class RmaLineMakeRmaOrderItem(models.TransientModel): related='line_id.product_id', readony=True) name = fields.Char(related='line_id.name', readonly=True) uom_id = fields.Many2one('product.uom', string='UoM', readonly=True) - product_qty = fields.Float(string='Quantity to sell', + product_qty = fields.Float(string='Quantity', digits=dp.get_precision('Product UoS')) diff --git a/rma/wizards/rma_order_line_make_supplier_rma_view.xml b/rma/wizards/rma_order_line_make_supplier_rma_view.xml index e7ad43c6..964c0e36 100644 --- a/rma/wizards/rma_order_line_make_supplier_rma_view.xml +++ b/rma/wizards/rma_order_line_make_supplier_rma_view.xml @@ -50,7 +50,7 @@ - Create Supplier RMA + Create Supplier RMA Group ir.actions.act_window rma.order.line.make.supplier.rma form @@ -61,7 +61,7 @@ - Create Supplier RMA + Create Supplier RMA Group client_action_multi @@ -77,7 +77,7 @@