From 92c8bb50dd24002dae6f67bc01fb67409b959db1 Mon Sep 17 00:00:00 2001 From: Jordi Ballester Date: Thu, 27 Jul 2017 18:17:19 +0200 Subject: [PATCH 01/50] init branch --- rma_sale/README.rst | 47 ++++++ rma_sale/__init__.py | 5 + rma_sale/__openerp__.py | 22 +++ rma_sale/models/__init__.py | 7 + rma_sale/models/rma_operation.py | 13 ++ rma_sale/models/rma_order.py | 41 +++++ rma_sale/models/rma_order_line.py | 92 +++++++++++ rma_sale/models/sale_order_line.py | 21 +++ rma_sale/views/rma_operation_view.xml | 28 ++++ rma_sale/views/rma_order_line_view.xml | 93 +++++++++++ rma_sale/views/rma_order_view.xml | 21 +++ rma_sale/views/sale_order_view.xml | 21 +++ rma_sale/wizards/__init__.py | 8 + rma_sale/wizards/rma_add_sale.py | 116 +++++++++++++ rma_sale/wizards/rma_add_sale.xml | 80 +++++++++ rma_sale/wizards/rma_make_picking.py | 20 +++ .../wizards/rma_order_line_make_sale_order.py | 155 ++++++++++++++++++ .../rma_order_line_make_sale_order_view.xml | 75 +++++++++ rma_sale/wizards/rma_refund.py | 23 +++ 19 files changed, 888 insertions(+) create mode 100644 rma_sale/README.rst create mode 100644 rma_sale/__init__.py create mode 100644 rma_sale/__openerp__.py create mode 100644 rma_sale/models/__init__.py create mode 100644 rma_sale/models/rma_operation.py create mode 100644 rma_sale/models/rma_order.py create mode 100644 rma_sale/models/rma_order_line.py create mode 100644 rma_sale/models/sale_order_line.py create mode 100644 rma_sale/views/rma_operation_view.xml create mode 100644 rma_sale/views/rma_order_line_view.xml create mode 100644 rma_sale/views/rma_order_view.xml create mode 100644 rma_sale/views/sale_order_view.xml create mode 100644 rma_sale/wizards/__init__.py create mode 100644 rma_sale/wizards/rma_add_sale.py create mode 100644 rma_sale/wizards/rma_add_sale.xml create mode 100644 rma_sale/wizards/rma_make_picking.py create mode 100644 rma_sale/wizards/rma_order_line_make_sale_order.py create mode 100644 rma_sale/wizards/rma_order_line_make_sale_order_view.xml create mode 100644 rma_sale/wizards/rma_refund.py diff --git a/rma_sale/README.rst b/rma_sale/README.rst new file mode 100644 index 00000000..f7d43adc --- /dev/null +++ b/rma_sale/README.rst @@ -0,0 +1,47 @@ +.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg + :alt: License LGPL-3 + +RMA Sale +======== + +This module allows you to: + +# . Import sales order lines into RMA lines +# . Create a sales order and/or sales order line from one or more RMA lines + +Usage +===== + +Import existing sales order lines into an RMA +--------------------------------------------- +This feature is useful when you create an RMA associated to a product that +was shipped and you have as a reference the customer PO number. + +#. Access to a customer RMA +#. Press the button "Add from Sales Order" + + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +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 +======= + +Contributors +------------ + +* Jordi Ballester Alomar +* Aaron Henriquez + + +Maintainer +---------- + +This module is maintained by Eficent diff --git a/rma_sale/__init__.py b/rma_sale/__init__.py new file mode 100644 index 00000000..4105ff51 --- /dev/null +++ b/rma_sale/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +from . import models +from . import wizards diff --git a/rma_sale/__openerp__.py b/rma_sale/__openerp__.py new file mode 100644 index 00000000..68635df2 --- /dev/null +++ b/rma_sale/__openerp__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +{ + 'name': 'RMA Sale', + 'version': '9.0.1.0.0', + 'license': 'LGPL-3', + 'category': 'RMA', + 'summary': 'Links RMA with Sales Orders', + 'author': "Eficent", + 'website': 'http://www.github.com/OCA/rma', + 'depends': ['rma_account', 'sale_stock'], + 'data': ['views/rma_order_view.xml', + 'views/rma_operation_view.xml', + 'views/sale_order_view.xml', + 'wizards/rma_order_line_make_sale_order_view.xml', + 'wizards/rma_add_sale.xml', + 'views/rma_order_line_view.xml'], + 'installable': True, + 'auto_install': True, +} diff --git a/rma_sale/models/__init__.py b/rma_sale/models/__init__.py new file mode 100644 index 00000000..0ec7edb9 --- /dev/null +++ b/rma_sale/models/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +from . import sale_order_line +from . import rma_order_line +from . import rma_order +from . import rma_operation diff --git a/rma_sale/models/rma_operation.py b/rma_sale/models/rma_operation.py new file mode 100644 index 00000000..08ad757c --- /dev/null +++ b/rma_sale/models/rma_operation.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +from openerp import _, api, fields, models + + +class RmaOperation(models.Model): + _inherit = 'rma.operation' + + sale_type = fields.Selection([ + ('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'), + ('received', 'Based on Received Quantities')], + string="Sale Policy", default='no') diff --git a/rma_sale/models/rma_order.py b/rma_sale/models/rma_order.py new file mode 100644 index 00000000..a97124b6 --- /dev/null +++ b/rma_sale/models/rma_order.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +from openerp import _, api, fields, models +from openerp.addons import decimal_precision as dp + + +class RmaOrder(models.Model): + _inherit = "rma.order" + + @api.one + def _compute_sales_count(self): + sales_list = [] + for rma_line in self.rma_line_ids: + if rma_line.sale_line_id and rma_line.sale_line_id.id: + sales_list.append(rma_line.sale_line_id.order_id.id) + self.sale_count = len(list(set(sales_list))) + + sale_count = fields.Integer(compute=_compute_sales_count, + string='# of Sales', copy=False, default=0) + + @api.model + def _get_line_domain(self, rma_id, line): + if line.sale_line_id and line.sale_line_id.id: + domain = [('rma_id', '=', rma_id.id), + ('type', '=', 'supplier'), + ('sale_line_id', '=', line.sale_line_id.id)] + else: + domain = super(RmaOrder, self)._get_line_domain(rma_id, line) + return domain + + @api.multi + def action_view_sale_order(self): + action = self.env.ref('sale.action_quotations') + result = action.read()[0] + order_ids = [] + for rma_line in self.rma_line_ids: + if rma_line.sale_line_id and rma_line.sale_line_id.id: + order_ids.append(rma_line.sale_line_id.order_id.id) + result['domain'] = [('id', 'in', order_ids)] + return result \ No newline at end of file diff --git a/rma_sale/models/rma_order_line.py b/rma_sale/models/rma_order_line.py new file mode 100644 index 00000000..e6be59ec --- /dev/null +++ b/rma_sale/models/rma_order_line.py @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +from openerp import _, api, fields, models +from openerp.addons import decimal_precision as dp + +class RmaOrderLine(models.Model): + _inherit = "rma.order.line" + + @api.model + def _default_sale_type(self): + return self.sale_type or False + + sale_type = fields.Selection([ + ('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'), + ('received', 'Based on Received Quantities')], + string="Sale Policy", default=_default_sale_type) + + @api.one + @api.depends('sale_line_ids', 'sale_type', 'sales_count', + 'sale_line_ids.state') + def _compute_qty_to_sell(self): + if self.sale_type == 'no': + self.qty_to_sell = 0.0 + elif self.sale_type == 'ordered': + qty = self._get_rma_sold_qty() + self.qty_to_sell = self.product_qty - qty + elif self.sale_type == 'received': + qty = self._get_rma_sold_qty() + self.qty_to_sell = self.qty_received - qty + else: + self.qty_to_sell = 0.0 + + @api.one + @api.depends('sale_line_ids', 'sale_type', 'sales_count', + 'sale_line_ids.state') + def _compute_qty_sold(self): + self.qty_sold = self._get_rma_sold_qty() + + @api.one + def _compute_sales_count(self): + sales_list = [] + for sale_order_line in self.sale_line_ids: + sales_list.append(sale_order_line.order_id.id) + self.sales_count = len(list(set(sales_list))) + + sale_line_id = fields.Many2one(comodel_name='sale.order.line', + string='Originating Sales Order Line', + ondelete='restrict') + sale_line_ids = fields.One2many(comodel_name='sale.order.line', + inverse_name='rma_line_id', + string='Sales Order Lines', readonly=True, + states={'draft': [('readonly', False)]}, + copy=False) + qty_to_sell = fields.Float( + string='Qty To Sell', copy=False, + digits=dp.get_precision('Product Unit of Measure'), + readonly=True, compute=_compute_qty_to_sell, + store=True) + + qty_sold = fields.Float( + string='Qty Sold', copy=False, + digits=dp.get_precision('Product Unit of Measure'), + readonly=True, compute=_compute_qty_sold, + store=True) + + sale_type = fields.Selection([ + ('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'), + ('received', 'Based on Received Quantities')], + string="Sale Policy", default='no', required=True) + + sales_count = fields.Integer(compute=_compute_sales_count, + string='# of Sales', copy=False, default=0) + + @api.multi + def action_view_sale_order(self): + action = self.env.ref('sale.action_quotations') + result = action.read()[0] + order_ids = [] + for sale_line in self.sale_line_ids: + order_ids.append(sale_line.order_id.id) + result['domain'] = [('id', 'in', order_ids)] + return result + + @api.multi + def _get_rma_sold_qty(self): + self.ensure_one() + qty = 0.0 + for sale_line in self.sale_line_ids.filtered( + lambda p: p.state not in ('draft', 'sent', 'cancel')): + qty += sale_line.product_uom_qty + return qty diff --git a/rma_sale/models/sale_order_line.py b/rma_sale/models/sale_order_line.py new file mode 100644 index 00000000..b54f8d81 --- /dev/null +++ b/rma_sale/models/sale_order_line.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from openerp import api, fields, models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + rma_line_id = fields.Many2one('rma.order.line', string='RMA', + ondelete='restrict') + + @api.multi + def _prepare_order_line_procurement(self, group_id=False): + vals = super(SaleOrderLine, self)._prepare_order_line_procurement( + group_id=group_id) + vals.update({ + 'rma_line_id': self.rma_line_id.id + }) + return vals diff --git a/rma_sale/views/rma_operation_view.xml b/rma_sale/views/rma_operation_view.xml new file mode 100644 index 00000000..cd97ee1d --- /dev/null +++ b/rma_sale/views/rma_operation_view.xml @@ -0,0 +1,28 @@ + + + + + + rma.operation.tree + rma.operation + + + + + + + + + + rma.operation.form + rma.operation + + + + + + + + + + diff --git a/rma_sale/views/rma_order_line_view.xml b/rma_sale/views/rma_order_line_view.xml new file mode 100644 index 00000000..9930bfd8 --- /dev/null +++ b/rma_sale/views/rma_order_line_view.xml @@ -0,0 +1,93 @@ + + + + + + rma.order.line.form + rma.order.line + + +
+ +
+ + + + + + + + + + + + + + + +
+ + + rma.order.line.supplier.form + rma.order.line + + +
+ +
+ + + + + + + + + + + + + + + +
+ + + rma.order.line.form + rma.order.line + + +
+
+
+
+ + rma.order.line.supplier.form + rma.order.line + + +
+
+
+
+ +
+
diff --git a/rma_sale/views/rma_order_view.xml b/rma_sale/views/rma_order_view.xml new file mode 100644 index 00000000..48ff6f61 --- /dev/null +++ b/rma_sale/views/rma_order_view.xml @@ -0,0 +1,21 @@ + + + + + rma.order.form + rma.order + + +
+ +
+
+
+
+
diff --git a/rma_sale/views/sale_order_view.xml b/rma_sale/views/sale_order_view.xml new file mode 100644 index 00000000..2bfe7ca4 --- /dev/null +++ b/rma_sale/views/sale_order_view.xml @@ -0,0 +1,21 @@ + + + + + sale.order.form + sale.order + + + + + + + + + + + diff --git a/rma_sale/wizards/__init__.py b/rma_sale/wizards/__init__.py new file mode 100644 index 00000000..40e8ecb8 --- /dev/null +++ b/rma_sale/wizards/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from . import rma_order_line_make_sale_order +from . import rma_make_picking +from . import rma_refund +from . import rma_add_sale diff --git a/rma_sale/wizards/rma_add_sale.py b/rma_sale/wizards/rma_add_sale.py new file mode 100644 index 00000000..1ed460fd --- /dev/null +++ b/rma_sale/wizards/rma_add_sale.py @@ -0,0 +1,116 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +import time +from openerp import models, fields, exceptions, api, _ +from openerp.exceptions import ValidationError +from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT as DT_FORMAT +import openerp.addons.decimal_precision as dp + + +class RmaAddSale(models.TransientModel): + _name = 'rma_add_sale' + _description = 'Wizard to add rma lines' + + @api.model + def default_get(self, fields): + res = super(RmaAddSale, self).default_get(fields) + rma_obj = self.env['rma.order'] + rma_id = self.env.context['active_ids'] or [] + active_model = self.env.context['active_model'] + if not rma_id: + return res + assert active_model == 'rma.order', 'Bad context propagation' + + rma = rma_obj.browse(rma_id) + res['rma_id'] = rma.id + res['partner_id'] = rma.partner_id.id + res['sale_id'] = False + res['sale_line_ids'] = False + return res + + rma_id = fields.Many2one('rma.order', + string='RMA Order', + readonly=True, + ondelete='cascade') + + partner_id = fields.Many2one(comodel_name='res.partner', string='Partner', + readonly=True) + sale_id = fields.Many2one(comodel_name='sale.order', string='Order') + sale_line_ids = fields.Many2many('sale.order.line', + 'rma_add_sale_add_line_rel', + 'sale_line_id', 'rma_add_sale_id', + readonly=False, + string='Sale Lines') + + def _prepare_rma_line_from_sale_order_line(self, line): + operation = line.product_id.rma_operation_id and \ + line.product_id.rma_operation_id.id or False + if not operation: + operation = line.product_id.categ_id.rma_operation_id and \ + line.product_id.categ_id.rma_operation_id.id or False + data = { + 'sale_line_id': line.id, + 'product_id': line.product_id.id, + 'origin': line.order_id.name, + 'uom_id': line.product_uom.id, + 'operation_id': operation, + 'product_qty': line.product_uom_qty, + 'delivery_address_id': self.sale_id.partner_id.id, + 'invoice_address_id': self.sale_id.partner_id.id, + 'price_unit': line.currency_id.compute( + line.price_unit, line.currency_id, round=False), + 'rma_id': self.rma_id.id + } + if not operation: + operation = self.env['rma.operation'].search( + [('type', '=', self.rma_id.type)], limit=1) + if not operation: + raise ValidationError("Please define an operation first") + 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") + data.update( + {'in_route_id': operation.in_route_id.id or route, + 'out_route_id': operation.out_route_id.id or route, + 'receipt_policy': operation.receipt_policy, + 'location_id': operation.location_id.id or + self.env.ref('stock.stock_location_stock').id, + 'operation_id': operation.id, + 'refund_policy': operation.refund_policy, + 'delivery_policy': operation.delivery_policy + }) + return data + + @api.model + def _get_rma_data(self): + data = { + 'date_rma': fields.Datetime.now(), + 'delivery_address_id': self.sale_id.partner_id.id, + 'invoice_address_id': self.sale_id.partner_id.id + } + return data + + @api.model + def _get_existing_sale_lines(self): + existing_sale_lines = [] + for rma_line in self.rma_id.rma_line_ids: + existing_sale_lines.append(rma_line.sale_line_id) + return existing_sale_lines + + @api.multi + def add_lines(self): + rma_line_obj = self.env['rma.order.line'] + existing_sale_lines = self._get_existing_sale_lines() + for line in self.sale_line_ids: + # Load a PO line only once + if line not in existing_sale_lines: + data = self._prepare_rma_line_from_sale_order_line(line) + rma_line_obj.create(data) + rma = self.rma_id + data_rma = self._get_rma_data() + rma.write(data_rma) + return {'type': 'ir.actions.act_window_close'} diff --git a/rma_sale/wizards/rma_add_sale.xml b/rma_sale/wizards/rma_add_sale.xml new file mode 100644 index 00000000..280dcbbc --- /dev/null +++ b/rma_sale/wizards/rma_add_sale.xml @@ -0,0 +1,80 @@ + + + + + rma.add.sale + rma_add_sale + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+ + + Add Sale Order + ir.actions.act_window + rma_add_sale + rma.order + form + form + new + + + + + + + rma.order.line.form + rma.order + + + + + + +
diff --git a/rma_sale/wizards/rma_make_picking.py b/rma_sale/wizards/rma_make_picking.py new file mode 100644 index 00000000..7291d4be --- /dev/null +++ b/rma_sale/wizards/rma_make_picking.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +from openerp import models, fields, exceptions, api, _ + + +class RmaMakePicking(models.TransientModel): + _inherit = 'rma_make_picking.wizard' + + @api.returns('rma.order.line') + def _prepare_item(self, line): + res = super(RmaMakePicking, self)._prepare_item(line) + res['sale_line_id'] = line.sale_line_id.id + return res + +class RmaMakePickingItem(models.TransientModel): + _inherit = "rma_make_picking.wizard.item" + + sale_line_id = fields.Many2one('sale.order.line', + string='Sale Line') diff --git a/rma_sale/wizards/rma_order_line_make_sale_order.py b/rma_sale/wizards/rma_order_line_make_sale_order.py new file mode 100644 index 00000000..68057f59 --- /dev/null +++ b/rma_sale/wizards/rma_order_line_make_sale_order.py @@ -0,0 +1,155 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0). + +import openerp.addons.decimal_precision as dp +from openerp import _, api, exceptions, fields, models + + +class RmaLineMakeSaleOrder(models.TransientModel): + _name = "rma.order.line.make.sale.order" + _description = "RMA Line Make Sales Order" + + partner_id = fields.Many2one('res.partner', string='Customer', + required=False, + domain=[('supplier', '=', True)]) + item_ids = fields.One2many( + 'rma.order.line.make.sale.order.item', + 'wiz_id', string='Items') + sale_order_id = fields.Many2one('sale.order', + string='Sales Order', + required=False, + domain=[('state', '=', 'draft')]) + + @api.model + def _prepare_item(self, line): + return { + 'line_id': line.id, + 'rma_line_id': line.id, + 'product_id': line.product_id.id, + 'name': line.product_id.name, + 'product_qty': line.qty_to_sell, + 'rma_id': line.rma_id.id, + 'out_warehouse_id': line.out_warehouse_id.id, + 'out_route_id': line.out_route_id.id, + 'product_uom_id': line.uom_id.id, + } + + @api.model + def default_get(self, fields): + res = super(RmaLineMakeSaleOrder, self).default_get( + fields) + rma_line_obj = self.env['rma.order.line'] + rma_line_ids = self.env.context['active_ids'] or [] + active_model = self.env.context['active_model'] + + if not rma_line_ids: + return res + assert active_model == 'rma.order.line', 'Bad context propagation' + + items = [] + lines = rma_line_obj.browse(rma_line_ids) + for line in lines: + items.append([0, 0, self._prepare_item(line)]) + customers = lines.mapped('partner_id') + if len(customers) == 1: + res['partner_id'] = customers.id + else: + raise exceptions.Warning( + _('Only RMA lines from the same partner can be processed at ' + 'the same time')) + res['item_ids'] = items + return res + + @api.model + def _prepare_sale_order(self, out_warehouse, company): + if not self.partner_id: + raise exceptions.Warning( + _('Enter a customer.')) + customer = self.partner_id + data = { + 'origin': '', + 'partner_id': customer.id, + 'warehouse_id': out_warehouse.id, + 'company_id': company.id, + } + return data + + @api.model + def _prepare_sale_order_line(self, so, item): + product = item.product_id + vals = { + 'name': product.name, + 'order_id': so.id, + 'product_id': product.id, + 'product_uom': product.uom_po_id.id, + 'route_id': item.out_route_id.id, + 'product_uom_qty': item.product_qty, + 'rma_line_id': item.line_id.id + } + if item.free_of_charge: + vals['price_unit'] = 0.0 + return vals + + @api.multi + def make_sale_order(self): + res = [] + sale_obj = self.env['sale.order'] + so_line_obj = self.env['sale.order.line'] + sale = False + + for item in self.item_ids: + line = item.line_id + if item.product_qty <= 0.0: + raise exceptions.Warning( + _('Enter a positive quantity.')) + + 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) + sale = sale_obj.create(po_data) + + so_line_data = self._prepare_sale_order_line(sale, item) + so_line_obj.create(so_line_data) + res.append(sale.id) + + return { + 'domain': "[('id','in', ["+','.join(map(str, res))+"])]", + 'name': _('Quotations'), + 'view_type': 'form', + 'view_mode': 'tree,form', + 'res_model': 'sale.order', + 'view_id': False, + 'context': False, + 'type': 'ir.actions.act_window' + } + + +class RmaLineMakeSaleOrderItem(models.TransientModel): + _name = "rma.order.line.make.sale.order.item" + _description = "RMA Line Make Sale Order Item" + + wiz_id = fields.Many2one( + 'rma.order.line.make.sale.order', + string='Wizard', required=True, ondelete='cascade', + readonly=True) + line_id = fields.Many2one('rma.order.line', + string='RMA Line', + required=True) + rma_id = fields.Many2one('rma.order', related='line_id.rma_id', + string='RMA Order', readonly=True) + product_id = fields.Many2one('product.product', string='Product', + readonly=True) + name = fields.Char(string='Description', required=True, readonly=True) + product_qty = fields.Float(string='Quantity to sell', + digits=dp.get_precision('Product UoS')) + product_uom_id = fields.Many2one('product.uom', string='UoM', + readonly=True) + out_warehouse_id = fields.Many2one('stock.warehouse', + string='Outbound Warehouse') + free_of_charge = fields.Boolean('Free of Charge') + out_route_id = fields.Many2one( + 'stock.location.route', string='Outbound Route', + domain=[('rma_selectable', '=', True)]) 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 new file mode 100644 index 00000000..fea59e77 --- /dev/null +++ b/rma_sale/wizards/rma_order_line_make_sale_order_view.xml @@ -0,0 +1,75 @@ + + + + + + RMA Line Make Sale Order + rma.order.line.make.sale.order + form + +
+ + + + /> + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/rma_sale/wizards/rma_add_sale.xml b/rma_sale/wizards/rma_add_sale.xml index 2a0c75b7..dd91f0dc 100644 --- a/rma_sale/wizards/rma_add_sale.xml +++ b/rma_sale/wizards/rma_add_sale.xml @@ -68,12 +68,11 @@ rma.order - + type="action"/> +
From 250330c7e15ff85828d1b73c8dfd8b68de374322 Mon Sep 17 00:00:00 2001 From: lreficent Date: Thu, 19 Oct 2017 11:29:08 +0200 Subject: [PATCH 10/50] [9.0][FIX] wizards need to specify partner. --- rma_sale/wizards/rma_add_sale.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rma_sale/wizards/rma_add_sale.py b/rma_sale/wizards/rma_add_sale.py index 64c4873a..a3e3d323 100644 --- a/rma_sale/wizards/rma_add_sale.py +++ b/rma_sale/wizards/rma_add_sale.py @@ -60,6 +60,7 @@ class RmaAddSale(models.TransientModel): raise ValidationError("Please define a warehouse with a " "default rma location.") data = { + 'partner_id': self.partner_id.id, 'sale_line_id': line.id, 'product_id': line.product_id.id, 'origin': line.order_id.name, From 11edbfb7ba84d782b3919af42e723c50b85e959c Mon Sep 17 00:00:00 2001 From: lreficent Date: Thu, 19 Oct 2017 16:07:02 +0200 Subject: [PATCH 11/50] fix rma_sale --- rma_sale/models/rma_order_line.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rma_sale/models/rma_order_line.py b/rma_sale/models/rma_order_line.py index f6addd10..c8037b74 100644 --- a/rma_sale/models/rma_order_line.py +++ b/rma_sale/models/rma_order_line.py @@ -38,7 +38,9 @@ class RmaOrderLine(models.Model): sale_line_id = fields.Many2one( comodel_name='sale.order.line', string='Originating Sales Order Line', - ondelete='restrict') + ondelete='restrict', copy=False, + readonly=True, states={'draft': [('readonly', False)]}, + ) sale_line_ids = fields.One2many( comodel_name='sale.order.line', inverse_name='rma_line_id', string='Sales Order Lines', readonly=True, From 8a5a344f011b0e57c73dc1cfd756f1b3458fda75 Mon Sep 17 00:00:00 2001 From: lreficent Date: Wed, 8 Nov 2017 16:06:18 +0100 Subject: [PATCH 12/50] [9.0][IMP] rma_sale: allow to search by order reference --- rma_sale/models/sale_order_line.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/rma_sale/models/sale_order_line.py b/rma_sale/models/sale_order_line.py index df0d6d46..9ffa5400 100644 --- a/rma_sale/models/sale_order_line.py +++ b/rma_sale/models/sale_order_line.py @@ -8,6 +8,25 @@ from openerp import api, fields, models class SaleOrderLine(models.Model): _inherit = "sale.order.line" + @api.model + def name_search(self, name='', args=None, operator='ilike', limit=100): + """Allows to search by SO reference.""" + if not args: + args = [] + args += ['|', + (self._rec_name, operator, name), + ('order_id.name', operator, name)] + return super(SaleOrderLine, self).name_search( + name=name, args=args, operator=operator, limit=limit) + + @api.model + def _name_search(self, name='', args=None, operator='ilike', + limit=100, name_get_uid=None): + """Typed text is cleared here for better extensibility.""" + return super(SaleOrderLine, self)._name_search( + name='', args=args, operator=operator, limit=limit, + name_get_uid=name_get_uid) + rma_line_id = fields.Many2one( comodel_name='rma.order.line', string='RMA', ondelete='restrict') From 585371524eb3588d19be0ef62a6f9fd10ade9c23 Mon Sep 17 00:00:00 2001 From: lreficent Date: Mon, 13 Nov 2017 14:05:26 +0100 Subject: [PATCH 13/50] [FIX] allow child partners too --- rma_sale/views/rma_order_line_view.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rma_sale/views/rma_order_line_view.xml b/rma_sale/views/rma_order_line_view.xml index dc8379df..f4fbb796 100644 --- a/rma_sale/views/rma_order_line_view.xml +++ b/rma_sale/views/rma_order_line_view.xml @@ -19,7 +19,9 @@ + domain="['|', + ('order_id.partner_id', '=', partner_id), + ('order_id.partner_id', 'child_of', partner_id)]"/> From 6163f8c507a29012c3c9322d53c75bf3f28fe85f Mon Sep 17 00:00:00 2001 From: lreficent Date: Mon, 13 Nov 2017 15:23:33 +0100 Subject: [PATCH 14/50] [9.0][IMP] rma: add link to source SO and PO --- rma_sale/models/rma_order_line.py | 4 ++++ rma_sale/views/rma_order_line_view.xml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/rma_sale/models/rma_order_line.py b/rma_sale/models/rma_order_line.py index c8037b74..1bc144f5 100644 --- a/rma_sale/models/rma_order_line.py +++ b/rma_sale/models/rma_order_line.py @@ -41,6 +41,10 @@ class RmaOrderLine(models.Model): ondelete='restrict', copy=False, readonly=True, states={'draft': [('readonly', False)]}, ) + sale_id = fields.Many2one( + string="Source Sales Order", related='sale_line_id.order_id', + readonly=True, + ) sale_line_ids = fields.One2many( comodel_name='sale.order.line', inverse_name='rma_line_id', string='Sales Order Lines', readonly=True, diff --git a/rma_sale/views/rma_order_line_view.xml b/rma_sale/views/rma_order_line_view.xml index f4fbb796..e0d45183 100644 --- a/rma_sale/views/rma_order_line_view.xml +++ b/rma_sale/views/rma_order_line_view.xml @@ -32,6 +32,10 @@ + + + From 5c45c2c3743bb03706b9882c6355d1fdea8c29be Mon Sep 17 00:00:00 2001 From: aheficent Date: Wed, 20 Dec 2017 10:21:32 +0100 Subject: [PATCH 15/50] [MIG]rma_sale to v10 --- rma_sale/{__openerp__.py => __manifest__.py} | 2 +- rma_sale/models/rma_operation.py | 2 +- rma_sale/models/rma_order.py | 2 +- rma_sale/models/rma_order_line.py | 6 +++--- rma_sale/models/sale_order_line.py | 2 +- rma_sale/wizards/rma_add_sale.py | 4 ++-- rma_sale/wizards/rma_make_picking.py | 2 +- rma_sale/wizards/rma_order_line_make_sale_order.py | 4 ++-- rma_sale/wizards/rma_refund.py | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) rename rma_sale/{__openerp__.py => __manifest__.py} (96%) diff --git a/rma_sale/__openerp__.py b/rma_sale/__manifest__.py similarity index 96% rename from rma_sale/__openerp__.py rename to rma_sale/__manifest__.py index 68635df2..0f440075 100644 --- a/rma_sale/__openerp__.py +++ b/rma_sale/__manifest__.py @@ -4,7 +4,7 @@ { 'name': 'RMA Sale', - 'version': '9.0.1.0.0', + 'version': '10.0.1.0.0', 'license': 'LGPL-3', 'category': 'RMA', 'summary': 'Links RMA with Sales Orders', diff --git a/rma_sale/models/rma_operation.py b/rma_sale/models/rma_operation.py index 500aadf5..a00f9a8d 100644 --- a/rma_sale/models/rma_operation.py +++ b/rma_sale/models/rma_operation.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # © 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -from openerp import fields, models +from odoo import fields, models class RmaOperation(models.Model): diff --git a/rma_sale/models/rma_order.py b/rma_sale/models/rma_order.py index c1069c95..952bcbcc 100644 --- a/rma_sale/models/rma_order.py +++ b/rma_sale/models/rma_order.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # © 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -from openerp import api, fields, models +from odoo import api, fields, models class RmaOrder(models.Model): diff --git a/rma_sale/models/rma_order_line.py b/rma_sale/models/rma_order_line.py index 1bc144f5..581915ad 100644 --- a/rma_sale/models/rma_order_line.py +++ b/rma_sale/models/rma_order_line.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- # © 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -from openerp import api, fields, models, _ -from openerp.exceptions import ValidationError -from openerp.addons import decimal_precision as dp +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError +from odoo.addons import decimal_precision as dp class RmaOrderLine(models.Model): diff --git a/rma_sale/models/sale_order_line.py b/rma_sale/models/sale_order_line.py index 9ffa5400..0687c034 100644 --- a/rma_sale/models/sale_order_line.py +++ b/rma_sale/models/sale_order_line.py @@ -2,7 +2,7 @@ # © 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -from openerp import api, fields, models +from odoo import api, fields, models class SaleOrderLine(models.Model): diff --git a/rma_sale/wizards/rma_add_sale.py b/rma_sale/wizards/rma_add_sale.py index a3e3d323..b33ed36d 100644 --- a/rma_sale/wizards/rma_add_sale.py +++ b/rma_sale/wizards/rma_add_sale.py @@ -2,8 +2,8 @@ # © 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -from openerp import api, fields, models -from openerp.exceptions import ValidationError +from odoo import api, fields, models +from odoo.exceptions import ValidationError class RmaAddSale(models.TransientModel): diff --git a/rma_sale/wizards/rma_make_picking.py b/rma_sale/wizards/rma_make_picking.py index 848e6a11..85ec2f71 100644 --- a/rma_sale/wizards/rma_make_picking.py +++ b/rma_sale/wizards/rma_make_picking.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # © 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -from openerp import api, fields, models +from odoo import api, fields, models class RmaMakePicking(models.TransientModel): 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 aaf37f8d..dee5fb73 100644 --- a/rma_sale/wizards/rma_order_line_make_sale_order.py +++ b/rma_sale/wizards/rma_order_line_make_sale_order.py @@ -2,8 +2,8 @@ # Copyright 2016 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0). -import openerp.addons.decimal_precision as dp -from openerp import _, api, exceptions, fields, models +import odoo.addons.decimal_precision as dp +from odoo import _, api, exceptions, fields, models class RmaLineMakeSaleOrder(models.TransientModel): diff --git a/rma_sale/wizards/rma_refund.py b/rma_sale/wizards/rma_refund.py index aa8f9af4..7ab7d032 100644 --- a/rma_sale/wizards/rma_refund.py +++ b/rma_sale/wizards/rma_refund.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # © 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -from openerp import api, fields, models +from odoo import api, fields, models class RmaRefund(models.TransientModel): From 2979c8ecc85feab990b05979ff6e272d3d118941 Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Fri, 10 Nov 2017 12:48:55 +0530 Subject: [PATCH 16/50] [IMP] Improved Unit Test Case and Fixed Travis --- rma_sale/__manifest__.py | 2 +- rma_sale/models/rma_order_line.py | 2 - rma_sale/tests/__init__.py | 6 + rma_sale/tests/test_rma.py | 451 ++++++++++++++++++++++++++++ rma_sale/tests/test_rma_dropship.py | 96 ++++++ rma_sale/tests/test_supplier_rma.py | 156 ++++++++++ 6 files changed, 710 insertions(+), 3 deletions(-) create mode 100644 rma_sale/tests/__init__.py create mode 100644 rma_sale/tests/test_rma.py create mode 100644 rma_sale/tests/test_rma_dropship.py create mode 100644 rma_sale/tests/test_supplier_rma.py diff --git a/rma_sale/__manifest__.py b/rma_sale/__manifest__.py index 0f440075..143bd704 100644 --- a/rma_sale/__manifest__.py +++ b/rma_sale/__manifest__.py @@ -8,7 +8,7 @@ 'license': 'LGPL-3', 'category': 'RMA', 'summary': 'Links RMA with Sales Orders', - 'author': "Eficent", + 'author': "Eficent, Odoo Community Association (OCA)", 'website': 'http://www.github.com/OCA/rma', 'depends': ['rma_account', 'sale_stock'], 'data': ['views/rma_order_view.xml', diff --git a/rma_sale/models/rma_order_line.py b/rma_sale/models/rma_order_line.py index 581915ad..53bc0f56 100644 --- a/rma_sale/models/rma_order_line.py +++ b/rma_sale/models/rma_order_line.py @@ -9,7 +9,6 @@ from odoo.addons import decimal_precision as dp class RmaOrderLine(models.Model): _inherit = "rma.order.line" - @api.one @api.depends('sale_line_ids', 'sale_type', 'sales_count', 'sale_line_ids.state') def _compute_qty_to_sell(self): @@ -24,7 +23,6 @@ class RmaOrderLine(models.Model): else: self.qty_to_sell = 0.0 - @api.one @api.depends('sale_line_ids', 'sale_type', 'sales_count', 'sale_line_ids.state') def _compute_qty_sold(self): diff --git a/rma_sale/tests/__init__.py b/rma_sale/tests/__init__.py new file mode 100644 index 00000000..dfa77946 --- /dev/null +++ b/rma_sale/tests/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +from . import test_rma +from . import test_supplier_rma +from . import test_rma_dropship diff --git a/rma_sale/tests/test_rma.py b/rma_sale/tests/test_rma.py new file mode 100644 index 00000000..586baca3 --- /dev/null +++ b/rma_sale/tests/test_rma.py @@ -0,0 +1,451 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from openerp.tests import common +from openerp import fields + + +class TestRma(common.TransactionCase): + + """ Test the routes and the quantities """ + + def setUp(self): + super(TestRma, self).setUp() + + self.rma_make_picking = self.env['rma_make_picking.wizard'] + self.make_supplier_rma = self.env["rma.order.line.make.supplier.rma"] + self.rma_add_stock_move = self.env['rma_add_stock_move'] + self.stockpicking = self.env['stock.picking'] + self.rma = self.env['rma.order'] + self.rma_line = self.env['rma.order.line'] + self.rma_op = self.env['rma.operation'] + self.rma_cust_replace_op_id = self.env.ref( + 'rma.rma_operation_customer_replace') + self.rma_sup_replace_op_id = self.env.ref( + 'rma.rma_operation_supplier_replace') + self.product_id = self.env.ref('product.product_product_4') + self.product_1 = self.env.ref('product.product_product_25') + self.product_2 = self.env.ref('product.product_product_30') + self.product_3 = self.env.ref('product.product_product_33') + self.uom_unit = self.env.ref('product.product_uom_unit') + # assign an operation + self.product_1.write( + {'rma_customer_operation_id': self.rma_cust_replace_op_id.id, + 'rma_supplier_operation_id': self.rma_sup_replace_op_id.id}) + self.product_2.write( + {'rma_customer_operation_id': self.rma_cust_replace_op_id.id, + 'rma_supplier_operation_id': self.rma_sup_replace_op_id.id}) + self.product_3.write( + {'rma_customer_operation_id': self.rma_cust_replace_op_id.id, + 'rma_supplier_operation_id': self.rma_sup_replace_op_id.id}) + self.partner_id = self.env.ref('base.res_partner_12') + self.stock_location = self.env.ref('stock.stock_location_stock') + self.stock_rma_location = self.env.ref('rma.location_rma') + self.customer_location = self.env.ref( + 'stock.stock_location_customers') + self.supplier_location = self.env.ref( + 'stock.stock_location_suppliers') + self.product_uom_id = self.env.ref('product.product_uom_unit') + products2move = [(self.product_1, 3), (self.product_2, 5), + (self.product_3, 2)] + self.rma_customer_id = self._create_rma_from_move( + products2move, 'customer', self.env.ref('base.res_partner_2'), + dropship=False) + + def _create_picking(self, partner): + return self.stockpicking.create({ + 'partner_id': partner.id, + 'picking_type_id': self.env.ref('stock.picking_type_in').id, + 'location_id': self.stock_location.id, + 'location_dest_id': self.supplier_location.id + }) + + def _create_rma_from_move(self, products2move, type, partner, dropship, + supplier_address_id=None): + picking_in = self._create_picking(partner) + + moves = [] + if type == 'customer': + for item in products2move: + move_values = self._prepare_move( + item[0], item[1], self.stock_location, + self.customer_location, picking_in) + moves.append(self.env['stock.move'].create(move_values)) + else: + for item in products2move: + move_values = self._prepare_move( + item[0], item[1], self.supplier_location, + self.stock_rma_location, picking_in) + moves.append(self.env['stock.move'].create(move_values)) + # Create the RMA from the stock_move + rma_id = self.rma.create( + { + 'reference': '0001', + 'type': type, + 'partner_id': partner.id, + 'company_id': self.env.ref('base.main_company').id + }) + for move in moves: + if type == 'customer': + wizard = self.rma_add_stock_move.with_context( + {'stock_move_id': move.id, 'customer': True, + 'active_ids': rma_id.id, + 'active_model': 'rma.order', + } + ).create({}) + data = wizard._prepare_rma_line_from_stock_move(move) + wizard.add_lines() + else: + wizard = self.rma_add_stock_move.with_context( + {'stock_move_id': move.id, 'supplier': True, + 'active_ids': rma_id.id, + 'active_model': 'rma.order', + } + ).create({}) + data = wizard._prepare_rma_line_from_stock_move(move) + wizard.add_lines() + if dropship: + data.update(customer_to_supplier=dropship, + supplier_address_id=supplier_address_id.id) + self.line = self.rma_line.create(data) + # approve the RMA Line + self.rma_line.action_rma_to_approve() + self.line.action_rma_approve() + rma_id._compute_in_shipment_count() + rma_id._compute_out_shipment_count() + rma_id._compute_supplier_line_count() + rma_id._compute_line_count() + rma_id.action_view_in_shipments() + rma_id.action_view_out_shipments() + rma_id.action_view_lines() + + rma_id.partner_id.action_open_partner_rma() + rma_id.partner_id._compute_rma_line_count() + # approve the RMA +# rma_id.action_rma_to_approve() +# rma_id.action_rma_approve() + return rma_id + + def _prepare_move(self, product, qty, src, dest, picking_in): + res = { + 'partner_id': self.partner_id.id, + 'product_id': product.id, + 'name': product.partner_ref, + 'state': 'confirmed', + 'product_uom': self.product_uom_id.id or product.uom_id.id, + 'product_uom_qty': qty, + 'origin': 'Test RMA', + 'location_id': src.id, + 'location_dest_id': dest.id, + 'picking_id': picking_in.id + } + return res + + def test_add_sale(self): + wizard = self.env['rma_add_sale'].with_context({ + 'active_ids': self.rma_customer_id.ids, + 'active_model': 'rma.order', + 'active_id': self.rma_customer_id.id + }).create({'partner_id': self.partner_id.id, + 'rma_id': self.rma_customer_id.id, + 'sale_id': self._create_sale_order().id, + 'sale_line_ids': + [(6, 0, [self._create_sale_order().order_line.id])], + }) + wizard.default_get([str(self._create_sale_order().id), + str(self._create_sale_order().order_line.id), + str(self.partner_id.id)]) + wizard.add_lines() + + for line in self.rma_customer_id.rma_line_ids: + line._compute_qty_to_sell() + line.sale_type = 'ordered' + line._compute_qty_to_sell() + line.sale_type = 'received' + line._compute_qty_to_sell() + line._compute_qty_sold() + line._compute_sales_count() + + data = {'sale_line_id': self._create_sale_order().order_line.id} + new_line = self.rma_line.new(data) + new_line._onchange_sale_line_id() + + line.action_view_sale_order() + self.rma_customer_id._compute_sales_count() + self.rma_customer_id.action_view_sale_order() + + def test_rma_order_line_make_sale_order(self): + + self.rma_sale_order_item =\ + self.env['rma.order.line.make.sale.order.item'] + self.rma_sale_order = self.env['rma.order.line.make.sale.order'] + + self.product_id.income =\ + self.env.ref('account.data_account_type_receivable').id + self.product_id.expense =\ + self.env.ref('account.data_account_type_expenses').id + + sale_order = self.rma_sale_order.with_context({ + 'active_ids': self.rma_customer_id.rma_line_ids.ids, + 'active_model': 'rma.order.line', + 'active_id': 1 + }).create({'sale_order_id': self._create_sale_order().id, + 'partner_id': self.partner_id.id, + }) + self.rma_sale_order_item.create({ + 'line_id': self.rma_customer_id.rma_line_ids[0].id, + 'rma_id': self.rma_customer_id.id, + 'product_id': self.product_id.id, + 'name': 'Test RMA Refund', + 'product_qty': self.rma_customer_id.rma_line_ids[0].product_qty, + 'wiz_id': sale_order.id + }) + for line in sale_order.item_ids: + line.product_qty = self.rma_customer_id.rma_line_ids[0].product_qty + sale_order.make_sale_order() + sale_order.write({'sale_order_id': False}) + sale_order.make_sale_order() + + def test_rma_refund(self): + + self.rma_refund_item = self.env['rma.refund.item'] + self.rma_refund = self.env['rma.refund'] + + self.product_id.income =\ + self.env.ref('account.data_account_type_receivable').id + self.product_id.expense =\ + self.env.ref('account.data_account_type_expenses').id + + self.product_id.product_tmpl_id.categ_id.\ + property_stock_account_input_categ_id =\ + self.env.ref('account.data_account_type_receivable').id + self.product_id.product_tmpl_id.categ_id.\ + property_stock_account_output_categ_id =\ + self.env.ref('account.data_account_type_expenses').id + + for line in self.rma_customer_id.rma_line_ids: + line.refund_policy = 'ordered' + + refund = self.rma_refund.with_context({ + 'active_ids': self.rma_customer_id.rma_line_ids.ids, + 'active_model': 'rma.order.line', + 'active_id': 1 + }).create({'description': 'Test Reason', + 'date_invoice': fields.datetime.now() + }) + self.rma_refund_item.create({ + 'line_id': self.rma_customer_id.rma_line_ids[0].id, + 'rma_id': self.rma_customer_id.id, + 'product_id': self.product_id.id, + 'name': 'Test RMA Refund', + 'product_qty': self.rma_customer_id.rma_line_ids[0].product_qty, + 'wiz_id': refund.id + }) + + def _create_sale_order(self): + self.sale_order_id = self.env['sale.order'].create({ + 'partner_id': self.partner_id.id, + 'partner_invoice_id': self.partner_id.id, + 'partner_shipping_id': self.partner_id.id, + 'order_line': [(0, 0, { + 'name': self.product_id.name, + 'product_id': self.product_id.id, + 'product_uom_qty': + self.rma_customer_id.rma_line_ids[0].product_qty, + 'price_unit': 100.00, + })] + }) + self.env["sale.order.line"].\ + name_search(name=self.product_id.name, operator='ilike', + args=[('id', 'in', self.sale_order_id.order_line.ids)]) + self.env["sale.order.line"].\ + _name_search(name=self.product_id.name, operator='ilike', + args=[('id', 'in', self.sale_order_id.order_line.ids) + ]) + self.sale_order_id.order_line._prepare_order_line_procurement() + return self.sale_order_id + + def test_rma_order_line(self): + for line in self.rma_customer_id.rma_line_ids: + line.with_context({'default_rma_id': line.rma_id.id + })._default_warehouse_id() + line._default_location_id() + line.with_context({'partner_id': line.rma_id.partner_id.id + })._default_delivery_address() + line._compute_in_shipment_count() + line._compute_out_shipment_count() + line._compute_procurement_count() + + data = {'reference_move_id': line.reference_move_id.id} + new_line = self.rma_line.new(data) + new_line._onchange_reference_move_id() + + line.action_rma_to_approve() + line.action_rma_draft() + line.action_rma_done() + + data = {'product_id': line.product_id.id} + new_line = self.rma_line.new(data) + new_line._onchange_product_id() + + data = {'operation_id': line.operation_id.id} + new_line = self.rma_line.new(data) + new_line._onchange_operation_id() + + data = {'customer_to_supplier': line.customer_to_supplier} + new_line = self.rma_line.new(data) + new_line._onchange_receipt_policy() + + data = {'lot_id': line.lot_id.id} + new_line = self.rma_line.new(data) + new_line._onchange_lot_id() + + line.action_view_in_shipments() + line.action_view_out_shipments() + line.action_view_procurements() + + def test_customer_rma(self): + wizard = self.rma_make_picking.with_context({ + 'active_ids': self.rma_customer_id.rma_line_ids.ids, + 'active_model': 'rma.order.line', + 'picking_type': 'incoming', + 'active_id': 1 + }).create({}) + procurements = wizard._create_picking() + group_ids = set([proc.group_id.id for proc in procurements if + proc.group_id]) + domain = [('group_id', 'in', list(group_ids))] + picking = self.stockpicking.search(domain) + self.assertEquals(len(picking), 1, + "Incorrect number of pickings created") + moves = picking.move_lines + self.assertEquals(len(moves), 3, + "Incorrect number of moves created") + for line in self.rma_customer_id.rma_line_ids: + # common qtys for all products + self.assertEquals(line.qty_received, 0, + "Wrong qty received") + self.assertEquals(line.qty_to_deliver, 0, + "Wrong qty to deliver") + self.assertEquals(line.qty_outgoing, 0, + "Wrong qty outgoing") + self.assertEquals(line.qty_delivered, 0, + "Wrong qty delivered") + # product specific + if line.product_id == self.product_1: + self.assertEquals(line.qty_to_receive, 3, + "Wrong qty to receive") + self.assertEquals(line.qty_incoming, 3, + "Wrong qty incoming") + if line.product_id == self.product_2: + self.assertEquals(line.qty_to_receive, 5, + "Wrong qty to receive") + self.assertEquals(line.qty_incoming, 5, + "Wrong qty incoming") + if line.product_id == self.product_3: + self.assertEquals(line.qty_to_receive, 2, + "Wrong qty to receive") + self.assertEquals(line.qty_incoming, 2, + "Wrong qty incoming") + picking.action_assign() + picking.do_transfer() + for line in self.rma_customer_id.rma_line_ids: + self.assertEquals(line.qty_to_receive, 0, + "Wrong qty to_receive") + self.assertEquals(line.qty_incoming, 0, + "Wrong qty incoming") + self.assertEquals(line.qty_outgoing, 0, + "Wrong qty outgoing") + self.assertEquals(line.qty_delivered, 0, + "Wrong qty delivered") + if line.product_id == self.product_1: + self.assertEquals(line.qty_received, 3, + "Wrong qty received") + self.assertEquals(line.qty_to_deliver, 3, + "Wrong qty to_deliver") + if line.product_id == self.product_2: + self.assertEquals(line.qty_received, 5, + "Wrong qty received") + self.assertEquals(line.qty_to_deliver, 5, + "Wrong qty to_deliver") + if line.product_id == self.product_3: + self.assertEquals(line.qty_received, 2, + "Wrong qty received") + self.assertEquals(line.qty_to_deliver, 2, + "Wrong qty to_deliver") + + wizard = self.rma_make_picking.with_context({ + 'active_id': 1, + 'active_ids': self.rma_customer_id.rma_line_ids.ids, + 'active_model': 'rma.order.line', + 'picking_type': 'outgoing', + }).create({}) + procurements = wizard._create_picking() + group_ids = set([proc.group_id.id for proc in procurements if + proc.group_id]) + domain = [('group_id', 'in', list(group_ids))] + pickings = self.stockpicking.search(domain) + self.assertEquals(len(pickings), 2, + "Incorrect number of pickings created") + picking_out = pickings[1] + moves = picking_out.move_lines + self.assertEquals(len(moves), 3, + "Incorrect number of moves created") + for line in self.rma_customer_id.rma_line_ids: + self.assertEquals(line.qty_to_receive, 0, + "Wrong qty to receive") + self.assertEquals(line.qty_incoming, 0, + "Wrong qty incoming") + self.assertEquals(line.qty_delivered, 0, + "Wrong qty delivered") + if line.product_id == self.product_1: + self.assertEquals(line.qty_to_deliver, 3, + "Wrong qty to deliver") + self.assertEquals(line.qty_outgoing, 3, + "Wrong qty outgoing") + self.assertEquals(line.qty_received, 3, + "Wrong qty received") + if line.product_id == self.product_2: + self.assertEquals(line.qty_received, 5, + "Wrong qty received") + self.assertEquals(line.qty_to_deliver, 5, + "Wrong qty to deliver") + self.assertEquals(line.qty_outgoing, 5, + "Wrong qty outgoing") + if line.product_id == self.product_3: + self.assertEquals(line.qty_received, 2, + "Wrong qty received") + self.assertEquals(line.qty_to_deliver, 2, + "Wrong qty to deliver") + self.assertEquals(line.qty_outgoing, 2, + "Wrong qty outgoing") + picking_out.action_assign() + picking_out.do_transfer() + for line in self.rma_customer_id.rma_line_ids: + self.assertEquals(line.qty_to_receive, 0, + "Wrong qty to receive") + self.assertEquals(line.qty_incoming, 0, + "Wrong qty incoming") + self.assertEquals(line.qty_to_deliver, 0, + "Wrong qty to deliver") + self.assertEquals(line.qty_outgoing, 0, + "Wrong qty outgoing") + if line.product_id == self.product_1: + self.assertEquals(line.qty_received, 3, + "Wrong qty received") + self.assertEquals(line.qty_delivered, 3, + "Wrong qty delivered") + if line.product_id == self.product_2: + self.assertEquals(line.qty_received, 5, + "Wrong qty received") + self.assertEquals(line.qty_delivered, 5, + "Wrong qty delivered") + if line.product_id == self.product_3: + self.assertEquals(line.qty_received, 2, + "Wrong qty received") + self.assertEquals(line.qty_delivered, 2, + "Wrong qty delivered") + self.line.action_rma_done() + self.assertEquals(self.line.state, 'done', + "Wrong State") diff --git a/rma_sale/tests/test_rma_dropship.py b/rma_sale/tests/test_rma_dropship.py new file mode 100644 index 00000000..9c99a538 --- /dev/null +++ b/rma_sale/tests/test_rma_dropship.py @@ -0,0 +1,96 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from . import test_rma + + +class TestRmaDropship(test_rma.TestRma): + + def setUp(self): + super(TestRmaDropship, self).setUp() + products2move = [(self.product_1, 3), (self.product_2, 5), + (self.product_3, 2)] + self.rma_droship_id = self._create_rma_from_move( + products2move, 'customer', self.env.ref('base.res_partner_2'), + dropship=True, + supplier_address_id=self.env.ref('base.res_partner_3')) + + def test_dropship(self): + wizard = self.make_supplier_rma.with_context({ + 'active_ids': self.rma_droship_id.rma_line_ids.ids, + 'active_model': 'rma.order.line', + 'active_id': 1 + }).create({}) + res = wizard.make_supplier_rma() + supplier_rma = self.rma.browse(res['res_id']) + for line in supplier_rma.rma_line_ids: + line.action_rma_to_approve() + line.action_rma_approve() + wizard = self.rma_make_picking.with_context({ + 'active_id': 1, + 'active_ids': supplier_rma.rma_line_ids.ids, + 'active_model': 'rma.order.line', + 'picking_type': 'incoming', + }).create({}) + procurements = wizard._create_picking() + group_ids = set([proc.group_id.id for proc in procurements if + proc.group_id]) + domain = [('group_id', 'in', list(group_ids))] + picking = self.stockpicking.search(domain) + self.assertEquals(len(picking), 1, + "Incorrect number of pickings created") + moves = picking.move_lines + self.assertEquals(len(moves), 3, + "Incorrect number of moves created") + for line in supplier_rma.rma_line_ids: + # common qtys for all products + self.assertEquals(line.qty_received, 0, + "Wrong qty received") + self.assertEquals(line.qty_outgoing, 0, + "Wrong qty incoming") + self.assertEquals(line.qty_delivered, 0, + "Wrong qty delivered") + # product specific + if line.product_id == self.product_1: + self.assertEquals(line.qty_to_receive, 3, + "Wrong qty to receive") + self.assertEquals(line.qty_to_deliver, 3, + "Wrong qty to deliver") + self.assertEquals(line.qty_incoming, 3, + "Wrong qty outgoing") + if line.product_id == self.product_2: + self.assertEquals(line.qty_to_receive, 5, + "Wrong qty to receive") + self.assertEquals(line.qty_to_deliver, 5, + "Wrong qty to deliver") + self.assertEquals(line.qty_incoming, 5, + "Wrong qty outgoing") + if line.product_id == self.product_3: + self.assertEquals(line.qty_to_receive, 2, + "Wrong qty to receive") + self.assertEquals(line.qty_to_deliver, 2, + "Wrong qty to deliver") + self.assertEquals(line.qty_incoming, 2, + "Wrong qty outgoing") + + for line in self.rma_droship_id.rma_line_ids: + if line.product_id == self.product_1: + self.assertEquals(line.qty_to_supplier_rma, 0, + "Wrong qty to supplier rma") + self.assertEquals(line.qty_in_supplier_rma, 3, + "Wrong qty in supplier rma") + if line.product_id == self.product_2: + self.assertEquals(line.qty_to_supplier_rma, 0, + "Wrong qty to supplier rma") + self.assertEquals(line.qty_in_supplier_rma, 5, + "Wrong qty in supplier rma") + if line.product_id == self.product_3: + self.assertEquals(line.qty_to_supplier_rma, 0, + "Wrong qty to supplier rma") + self.assertEquals(line.qty_in_supplier_rma, 2, + "Wrong qty in supplier rma") + for line in self.rma_droship_id.rma_line_ids: + line.action_rma_done() + self.assertEquals(line.state, 'done', + "Wrong State") diff --git a/rma_sale/tests/test_supplier_rma.py b/rma_sale/tests/test_supplier_rma.py new file mode 100644 index 00000000..8aa24518 --- /dev/null +++ b/rma_sale/tests/test_supplier_rma.py @@ -0,0 +1,156 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from . import test_rma + + +class TestSupplierRma(test_rma.TestRma): + + def setUp(self): + super(TestSupplierRma, self).setUp() + products2move = [(self.product_1, 3), (self.product_2, 5), + (self.product_3, 2)] + self.rma_supplier_id = self._create_rma_from_move( + products2move, 'supplier', self.env.ref('base.res_partner_1'), + dropship=False) + + def test_supplier_rma(self): + wizard = self.rma_make_picking.with_context({ + 'active_ids': self.rma_supplier_id.rma_line_ids.ids, + 'active_model': 'rma.order.line', + 'picking_type': 'outgoing', + 'active_id': 1 + }).create({}) + procurements = wizard._create_picking() + group_ids = set([proc.group_id.id for proc in procurements if + proc.group_id]) + domain = [('group_id', 'in', list(group_ids))] + picking = self.stockpicking.search(domain) + self.assertEquals(len(picking), 1, + "Incorrect number of pickings created") + moves = picking.move_lines + self.assertEquals(len(moves), 3, + "Incorrect number of moves created") + for line in self.rma_supplier_id.rma_line_ids: + # common qtys for all products + self.assertEquals(line.qty_received, 0, + "Wrong qty received") + self.assertEquals(line.qty_incoming, 0, + "Wrong qty incoming") + self.assertEquals(line.qty_delivered, 0, + "Wrong qty delivered") + # product specific + if line.product_id == self.product_1: + self.assertEquals(line.qty_to_receive, 3, + "Wrong qty to receive") + self.assertEquals(line.qty_to_deliver, 3, + "Wrong qty to deliver") + self.assertEquals(line.qty_outgoing, 3, + "Wrong qty outgoing") + if line.product_id == self.product_2: + self.assertEquals(line.qty_to_receive, 5, + "Wrong qty to receive") + self.assertEquals(line.qty_to_deliver, 5, + "Wrong qty to deliver") + self.assertEquals(line.qty_outgoing, 5, + "Wrong qty outgoing") + if line.product_id == self.product_3: + self.assertEquals(line.qty_to_receive, 2, + "Wrong qty to receive") + self.assertEquals(line.qty_to_deliver, 2, + "Wrong qty to deliver") + self.assertEquals(line.qty_outgoing, 2, + "Wrong qty outgoing") + + picking.action_assign() + picking.do_transfer() + for line in self.rma_supplier_id.rma_line_ids: + self.assertEquals(line.qty_incoming, 0, + "Wrong qty incoming") + self.assertEquals(line.qty_received, 0, + "Wrong qty received") + if line.product_id == self.product_1: + self.assertEquals(line.qty_delivered, 3, + "Wrong qty delivered") + self.assertEquals(line.qty_to_receive, 3, + "Wrong qty to receive") + if line.product_id == self.product_2: + self.assertEquals(line.qty_outgoing, 5, + "Wrong qty delivered") + self.assertEquals(line.qty_to_receive, 5, + "Wrong qty to receive") + if line.product_id == self.product_3: + self.assertEquals(line.qty_outgoing, 2, + "Wrong qty delivered") + self.assertEquals(line.qty_to_receive, 2, + "Wrong qty to receive") + wizard = self.rma_make_picking.with_context({ + 'active_id': 1, + 'active_ids': self.rma_supplier_id.rma_line_ids.ids, + 'active_model': 'rma.order.line', + 'picking_type': 'incoming', + }).create({}) + procurements = wizard._create_picking() + group_ids = set([proc.group_id.id for proc in procurements if + proc.group_id]) + domain = [('group_id', 'in', list(group_ids))] + pickings = self.stockpicking.search(domain) + self.assertEquals(len(pickings), 3, + "Incorrect number of pickings created") + picking_out = pickings[0] + moves = picking_out.move_lines + self.assertEquals(len(moves), 2, + "Incorrect number of moves created") + for line in self.rma_supplier_id.rma_line_ids: + self.assertEquals(line.qty_incoming, 0, + "Wrong qty incoming") + self.assertEquals(line.qty_received, 0, + "Wrong qty received") + if line.product_id == self.product_1: + self.assertEquals(line.qty_to_receive, 3, + "Wrong qty to receive") + self.assertEquals(line.qty_incoming, 0, + "Wrong qty incoming") + self.assertEquals(line.qty_delivered, 3, + "Wrong qty delivered") + if line.product_id == self.product_2: + self.assertEquals(line.qty_to_receive, 5, + "Wrong qty to receive") + self.assertEquals(line.qty_to_deliver, 5, + "Wrong qty to deliver") + if line.product_id == self.product_3: + self.assertEquals(line.qty_to_receive, 2, + "Wrong qty to receive") + self.assertEquals(line.qty_to_deliver, 2, + "Wrong qty to deliver") + picking_out.action_assign() + picking_out.do_transfer() + for line in self.rma_supplier_id.rma_line_ids[0]: + self.assertEquals(line.qty_to_receive, 3, + "Wrong qty to receive") + self.assertEquals(line.qty_incoming, 0, + "Wrong qty incoming") + self.assertEquals(line.qty_to_deliver, 0, + "Wrong qty to deliver") + self.assertEquals(line.qty_outgoing, 3, + "Wrong qty outgoing") + if line.product_id == self.product_1: + self.assertEquals(line.qty_received, 0, + "Wrong qty received") + self.assertEquals(line.qty_delivered, 3, + "Wrong qty delivered") + if line.product_id == self.product_2: + self.assertEquals(line.qty_received, 0, + "Wrong qty received") + self.assertEquals(line.qty_delivered, 5, + "Wrong qty delivered") + if line.product_id == self.product_3: + self.assertEquals(line.qty_received, 2, + "Wrong qty received") + self.assertEquals(line.qty_delivered, 2, + "Wrong qty delivered") + for line in self.rma_supplier_id.rma_line_ids: + line.action_rma_done() + self.assertEquals(line.state, 'done', + "Wrong State") From 5425e6c7d8e03383cdb6b9e480e003a2727a365a Mon Sep 17 00:00:00 2001 From: aheficent Date: Tue, 2 Jan 2018 13:05:09 +0100 Subject: [PATCH 17/50] [FIX]various fixes --- rma_sale/wizards/rma_add_sale.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rma_sale/wizards/rma_add_sale.py b/rma_sale/wizards/rma_add_sale.py index b33ed36d..de4ce988 100644 --- a/rma_sale/wizards/rma_add_sale.py +++ b/rma_sale/wizards/rma_add_sale.py @@ -2,7 +2,7 @@ # © 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -from odoo import api, fields, models +from odoo import _, api, fields, models from odoo.exceptions import ValidationError @@ -46,19 +46,19 @@ class RmaAddSale(models.TransientModel): operation = self.env['rma.operation'].search( [('type', '=', self.rma_id.type)], limit=1) if not operation: - raise ValidationError("Please define an operation first") + raise ValidationError(_("Please define an operation first")) 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") + 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.") + raise ValidationError(_("Please define a warehouse with a " + "default rma location.")) data = { 'partner_id': self.partner_id.id, 'sale_line_id': line.id, From 0007434665f906f8b72000f56e5d3292c4a79331 Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Fri, 5 Jan 2018 16:43:54 +0530 Subject: [PATCH 18/50] [MIG] Migrated UT & Fixed Travis --- rma_sale/tests/test_rma.py | 111 ++++++++++++++++------------ rma_sale/tests/test_supplier_rma.py | 32 ++++---- 2 files changed, 79 insertions(+), 64 deletions(-) diff --git a/rma_sale/tests/test_rma.py b/rma_sale/tests/test_rma.py index 586baca3..0e6229ad 100644 --- a/rma_sale/tests/test_rma.py +++ b/rma_sale/tests/test_rma.py @@ -26,8 +26,8 @@ class TestRma(common.TransactionCase): 'rma.rma_operation_supplier_replace') self.product_id = self.env.ref('product.product_product_4') self.product_1 = self.env.ref('product.product_product_25') - self.product_2 = self.env.ref('product.product_product_30') - self.product_3 = self.env.ref('product.product_product_33') + self.product_2 = self.env.ref('product.product_product_7') + self.product_3 = self.env.ref('product.product_product_11') self.uom_unit = self.env.ref('product.product_uom_unit') # assign an operation self.product_1.write( @@ -88,26 +88,47 @@ class TestRma(common.TransactionCase): }) for move in moves: if type == 'customer': - wizard = self.rma_add_stock_move.with_context( + wizard = self.rma_add_stock_move.new( {'stock_move_id': move.id, 'customer': True, 'active_ids': rma_id.id, + 'partner_id': move.partner_id.id, 'active_model': 'rma.order', } - ).create({}) + ) + wizard.with_context({ + 'stock_move_id': move.id, 'customer': True, + 'active_ids': rma_id.id, + 'partner_id': move.partner_id.id, + 'active_model': 'rma.order', + }) + data = wizard._prepare_rma_line_from_stock_move(move) + data['partner_id'] = move.partner_id.id wizard.add_lines() + else: - wizard = self.rma_add_stock_move.with_context( + wizard = self.rma_add_stock_move.new( {'stock_move_id': move.id, 'supplier': True, 'active_ids': rma_id.id, + 'partner_id': move.partner_id.id, 'active_model': 'rma.order', } - ).create({}) + ) + wizard.with_context( + {'stock_move_id': move.id, 'supplier': True, + 'active_ids': rma_id.id, + 'partner_id': move.partner_id.id, + 'active_model': 'rma.order', + }) + data = wizard._prepare_rma_line_from_stock_move(move) + data['partner_id'] = move.partner_id.id wizard.add_lines() if dropship: data.update(customer_to_supplier=dropship, supplier_address_id=supplier_address_id.id) + data['partner_id'] = move.partner_id.id + data['rma_id'] = rma_id.id self.line = self.rma_line.create(data) # approve the RMA Line self.rma_line.action_rma_to_approve() @@ -326,51 +347,47 @@ class TestRma(common.TransactionCase): # common qtys for all products self.assertEquals(line.qty_received, 0, "Wrong qty received") - self.assertEquals(line.qty_to_deliver, 0, - "Wrong qty to deliver") - self.assertEquals(line.qty_outgoing, 0, - "Wrong qty outgoing") + self.assertEquals(line.qty_incoming, 0, + "Wrong qty incoming") self.assertEquals(line.qty_delivered, 0, "Wrong qty delivered") # product specific if line.product_id == self.product_1: self.assertEquals(line.qty_to_receive, 3, "Wrong qty to receive") - self.assertEquals(line.qty_incoming, 3, + self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming") if line.product_id == self.product_2: self.assertEquals(line.qty_to_receive, 5, "Wrong qty to receive") - self.assertEquals(line.qty_incoming, 5, + self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming") if line.product_id == self.product_3: self.assertEquals(line.qty_to_receive, 2, "Wrong qty to receive") - self.assertEquals(line.qty_incoming, 2, + self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming") picking.action_assign() - picking.do_transfer() + picking.do_new_transfer() for line in self.rma_customer_id.rma_line_ids: - self.assertEquals(line.qty_to_receive, 0, - "Wrong qty to_receive") + self.assertEquals(line.qty_received, 0, + "Wrong qty receive") self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming") - self.assertEquals(line.qty_outgoing, 0, - "Wrong qty outgoing") self.assertEquals(line.qty_delivered, 0, "Wrong qty delivered") if line.product_id == self.product_1: - self.assertEquals(line.qty_received, 3, + self.assertEquals(line.qty_received, 0, "Wrong qty received") self.assertEquals(line.qty_to_deliver, 3, "Wrong qty to_deliver") if line.product_id == self.product_2: - self.assertEquals(line.qty_received, 5, + self.assertEquals(line.qty_received, 0, "Wrong qty received") self.assertEquals(line.qty_to_deliver, 5, "Wrong qty to_deliver") if line.product_id == self.product_3: - self.assertEquals(line.qty_received, 2, + self.assertEquals(line.qty_received, 0, "Wrong qty received") self.assertEquals(line.qty_to_deliver, 2, "Wrong qty to_deliver") @@ -393,8 +410,8 @@ class TestRma(common.TransactionCase): self.assertEquals(len(moves), 3, "Incorrect number of moves created") for line in self.rma_customer_id.rma_line_ids: - self.assertEquals(line.qty_to_receive, 0, - "Wrong qty to receive") + self.assertEquals(line.qty_received, 0, + "Wrong qty receive") self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming") self.assertEquals(line.qty_delivered, 0, @@ -402,50 +419,48 @@ class TestRma(common.TransactionCase): if line.product_id == self.product_1: self.assertEquals(line.qty_to_deliver, 3, "Wrong qty to deliver") - self.assertEquals(line.qty_outgoing, 3, + self.assertEquals(line.qty_outgoing, 6, "Wrong qty outgoing") - self.assertEquals(line.qty_received, 3, + self.assertEquals(line.qty_received, 0, "Wrong qty received") if line.product_id == self.product_2: - self.assertEquals(line.qty_received, 5, + self.assertEquals(line.qty_received, 0, "Wrong qty received") self.assertEquals(line.qty_to_deliver, 5, "Wrong qty to deliver") - self.assertEquals(line.qty_outgoing, 5, + self.assertEquals(line.qty_outgoing, 10, "Wrong qty outgoing") if line.product_id == self.product_3: - self.assertEquals(line.qty_received, 2, + self.assertEquals(line.qty_received, 0, "Wrong qty received") self.assertEquals(line.qty_to_deliver, 2, "Wrong qty to deliver") - self.assertEquals(line.qty_outgoing, 2, + self.assertEquals(line.qty_outgoing, 4, "Wrong qty outgoing") picking_out.action_assign() - picking_out.do_transfer() + picking_out.do_new_transfer() for line in self.rma_customer_id.rma_line_ids: - self.assertEquals(line.qty_to_receive, 0, - "Wrong qty to receive") + self.assertEquals(line.qty_received, 0, + "Wrong qty receive") self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming") - self.assertEquals(line.qty_to_deliver, 0, - "Wrong qty to deliver") - self.assertEquals(line.qty_outgoing, 0, - "Wrong qty outgoing") + self.assertEquals(line.qty_delivered, 0, + "Wrong qty deliver") if line.product_id == self.product_1: - self.assertEquals(line.qty_received, 3, - "Wrong qty received") - self.assertEquals(line.qty_delivered, 3, - "Wrong qty delivered") + self.assertEquals(line.qty_to_receive, 3, + "Wrong qty to received") + self.assertEquals(line.qty_to_deliver, 3, + "Wrong qty to delivered") if line.product_id == self.product_2: - self.assertEquals(line.qty_received, 5, - "Wrong qty received") - self.assertEquals(line.qty_delivered, 5, - "Wrong qty delivered") + self.assertEquals(line.qty_to_receive, 5, + "Wrong qty to received") + self.assertEquals(line.qty_to_deliver, 5, + "Wrong qty to delivered") if line.product_id == self.product_3: - self.assertEquals(line.qty_received, 2, - "Wrong qty received") - self.assertEquals(line.qty_delivered, 2, - "Wrong qty delivered") + self.assertEquals(line.qty_to_receive, 2, + "Wrong qty to received") + self.assertEquals(line.qty_to_deliver, 2, + "Wrong qty to delivered") self.line.action_rma_done() self.assertEquals(self.line.state, 'done', "Wrong State") diff --git a/rma_sale/tests/test_supplier_rma.py b/rma_sale/tests/test_supplier_rma.py index 8aa24518..64a1e1ff 100644 --- a/rma_sale/tests/test_supplier_rma.py +++ b/rma_sale/tests/test_supplier_rma.py @@ -76,12 +76,12 @@ class TestSupplierRma(test_rma.TestRma): self.assertEquals(line.qty_to_receive, 3, "Wrong qty to receive") if line.product_id == self.product_2: - self.assertEquals(line.qty_outgoing, 5, + self.assertEquals(line.qty_delivered, 5, "Wrong qty delivered") self.assertEquals(line.qty_to_receive, 5, "Wrong qty to receive") if line.product_id == self.product_3: - self.assertEquals(line.qty_outgoing, 2, + self.assertEquals(line.qty_delivered, 2, "Wrong qty delivered") self.assertEquals(line.qty_to_receive, 2, "Wrong qty to receive") @@ -96,11 +96,11 @@ class TestSupplierRma(test_rma.TestRma): proc.group_id]) domain = [('group_id', 'in', list(group_ids))] pickings = self.stockpicking.search(domain) - self.assertEquals(len(pickings), 3, + self.assertEquals(len(pickings), 2, "Incorrect number of pickings created") - picking_out = pickings[0] + picking_out = pickings[1] moves = picking_out.move_lines - self.assertEquals(len(moves), 2, + self.assertEquals(len(moves), 3, "Incorrect number of moves created") for line in self.rma_supplier_id.rma_line_ids: self.assertEquals(line.qty_incoming, 0, @@ -117,13 +117,13 @@ class TestSupplierRma(test_rma.TestRma): if line.product_id == self.product_2: self.assertEquals(line.qty_to_receive, 5, "Wrong qty to receive") - self.assertEquals(line.qty_to_deliver, 5, - "Wrong qty to deliver") + self.assertEquals(line.qty_delivered, 5, + "Wrong qty deliver") if line.product_id == self.product_3: self.assertEquals(line.qty_to_receive, 2, "Wrong qty to receive") - self.assertEquals(line.qty_to_deliver, 2, - "Wrong qty to deliver") + self.assertEquals(line.qty_delivered, 2, + "Wrong qty deliver") picking_out.action_assign() picking_out.do_transfer() for line in self.rma_supplier_id.rma_line_ids[0]: @@ -131,24 +131,24 @@ class TestSupplierRma(test_rma.TestRma): "Wrong qty to receive") self.assertEquals(line.qty_incoming, 0, "Wrong qty incoming") - self.assertEquals(line.qty_to_deliver, 0, - "Wrong qty to deliver") - self.assertEquals(line.qty_outgoing, 3, + self.assertEquals(line.qty_received, 0, + "Wrong qty receive") + self.assertEquals(line.qty_outgoing, 0, "Wrong qty outgoing") if line.product_id == self.product_1: self.assertEquals(line.qty_received, 0, "Wrong qty received") - self.assertEquals(line.qty_delivered, 3, + self.assertEquals(line.qty_delivered, 6, "Wrong qty delivered") if line.product_id == self.product_2: self.assertEquals(line.qty_received, 0, "Wrong qty received") - self.assertEquals(line.qty_delivered, 5, + self.assertEquals(line.qty_delivered, 10, "Wrong qty delivered") if line.product_id == self.product_3: - self.assertEquals(line.qty_received, 2, + self.assertEquals(line.qty_received, 0, "Wrong qty received") - self.assertEquals(line.qty_delivered, 2, + self.assertEquals(line.qty_delivered, 4, "Wrong qty delivered") for line in self.rma_supplier_id.rma_line_ids: line.action_rma_done() From 2166e7d2a0bb59f6619cb1c1057be025a8bc082a Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Tue, 9 Jan 2018 15:35:29 +0530 Subject: [PATCH 19/50] [IMP] Improved Code. --- rma_sale/tests/test_rma.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rma_sale/tests/test_rma.py b/rma_sale/tests/test_rma.py index 0e6229ad..57afd60c 100644 --- a/rma_sale/tests/test_rma.py +++ b/rma_sale/tests/test_rma.py @@ -193,6 +193,9 @@ class TestRma(common.TransactionCase): new_line._onchange_sale_line_id() line.action_view_sale_order() + self.rma_customer_id.\ + _get_line_domain(self.rma_customer_id, + self.rma_customer_id.rma_line_ids[3]) self.rma_customer_id._compute_sales_count() self.rma_customer_id.action_view_sale_order() From 64c560aac340059d1d5ab9ce4fdfcff64e85b6ea Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Wed, 10 Jan 2018 13:54:55 +0100 Subject: [PATCH 20/50] [FIX] Fixed UT & Travis --- rma_sale/__manifest__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rma_sale/__manifest__.py b/rma_sale/__manifest__.py index 143bd704..88bc95c9 100644 --- a/rma_sale/__manifest__.py +++ b/rma_sale/__manifest__.py @@ -10,7 +10,7 @@ 'summary': 'Links RMA with Sales Orders', 'author': "Eficent, Odoo Community Association (OCA)", 'website': 'http://www.github.com/OCA/rma', - 'depends': ['rma_account', 'sale_stock'], + 'depends': ['rma', 'rma_account', 'sale_stock'], 'data': ['views/rma_order_view.xml', 'views/rma_operation_view.xml', 'views/sale_order_view.xml', From 2e22da29ff8187a327b9b640c1c8e5b4b0297d04 Mon Sep 17 00:00:00 2001 From: aheficent Date: Thu, 8 Feb 2018 15:13:38 +0100 Subject: [PATCH 21/50] [FIX]compute qty to sell --- rma_sale/models/rma_order_line.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/rma_sale/models/rma_order_line.py b/rma_sale/models/rma_order_line.py index 53bc0f56..8db427b8 100644 --- a/rma_sale/models/rma_order_line.py +++ b/rma_sale/models/rma_order_line.py @@ -11,17 +11,19 @@ class RmaOrderLine(models.Model): @api.depends('sale_line_ids', 'sale_type', 'sales_count', 'sale_line_ids.state') + @api.multi def _compute_qty_to_sell(self): - if self.sale_type == 'no': - self.qty_to_sell = 0.0 - elif self.sale_type == 'ordered': - qty = self._get_rma_sold_qty() - self.qty_to_sell = self.product_qty - qty - elif self.sale_type == 'received': - qty = self._get_rma_sold_qty() - self.qty_to_sell = self.qty_received - qty - else: - self.qty_to_sell = 0.0 + for rec in self: + if rec.sale_type == 'no': + rec.qty_to_sell = 0.0 + elif rec.sale_type == 'ordered': + qty = self._get_rma_sold_qty() + rec.qty_to_sell = self.product_qty - qty + elif rec.sale_type == 'received': + qty = self._get_rma_sold_qty() + rec.qty_to_sell = self.qty_received - qty + else: + rec.qty_to_sell = 0.0 @api.depends('sale_line_ids', 'sale_type', 'sales_count', 'sale_line_ids.state') From c55f46bf30d697273ea84a79b77263444cbaf1fe Mon Sep 17 00:00:00 2001 From: Maxime Chambreuil Date: Fri, 9 Feb 2018 12:35:23 -0600 Subject: [PATCH 22/50] [MIG] Migrate configuration and cleanup --- rma_sale/__manifest__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rma_sale/__manifest__.py b/rma_sale/__manifest__.py index 88bc95c9..32335dbe 100644 --- a/rma_sale/__manifest__.py +++ b/rma_sale/__manifest__.py @@ -17,6 +17,6 @@ 'wizards/rma_order_line_make_sale_order_view.xml', 'wizards/rma_add_sale.xml', 'views/rma_order_line_view.xml'], - 'installable': True, + 'installable': False, 'auto_install': True, } From 8d1357f17b29db835c57cccea0fa78e0efe1f0c3 Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Wed, 18 Apr 2018 14:45:53 +0200 Subject: [PATCH 23/50] [FIX] tests --- rma_sale/tests/test_rma.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rma_sale/tests/test_rma.py b/rma_sale/tests/test_rma.py index 57afd60c..fca5f716 100644 --- a/rma_sale/tests/test_rma.py +++ b/rma_sale/tests/test_rma.py @@ -41,7 +41,8 @@ class TestRma(common.TransactionCase): 'rma_supplier_operation_id': self.rma_sup_replace_op_id.id}) self.partner_id = self.env.ref('base.res_partner_12') self.stock_location = self.env.ref('stock.stock_location_stock') - self.stock_rma_location = self.env.ref('rma.location_rma') + wh = self.env.ref('stock.warehouse0') + self.stock_rma_location = wh.lot_rma_id self.customer_location = self.env.ref( 'stock.stock_location_customers') self.supplier_location = self.env.ref( From f245cf377b81b26f45e438eba9b708d4db0e3d92 Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 4 May 2018 09:26:54 +0200 Subject: [PATCH 24/50] [FIX]reverting changes applied to v11 --- rma_sale/models/sale_order_line.py | 15 +++++++++++++++ rma_sale/views/rma_order_line_view.xml | 1 + 2 files changed, 16 insertions(+) diff --git a/rma_sale/models/sale_order_line.py b/rma_sale/models/sale_order_line.py index 0687c034..84041190 100644 --- a/rma_sale/models/sale_order_line.py +++ b/rma_sale/models/sale_order_line.py @@ -27,6 +27,21 @@ class SaleOrderLine(models.Model): name='', args=args, operator=operator, limit=limit, name_get_uid=name_get_uid) + @api.multi + def name_get(self): + res = [] + if self.env.context.get('rma'): + for sale in self: + if sale.order_id.name: + res.append((sale.id, "%s %s qty:%s" % ( + sale.order_id.name, + sale.product_id.name, sale.product_uom_qty))) + else: + res.append(super(SaleOrderLine, sale).name_get()[0]) + return res + else: + return super(SaleOrderLine, self).name_get() + rma_line_id = fields.Many2one( comodel_name='rma.order.line', string='RMA', ondelete='restrict') diff --git a/rma_sale/views/rma_order_line_view.xml b/rma_sale/views/rma_order_line_view.xml index e0d45183..d3d4199f 100644 --- a/rma_sale/views/rma_order_line_view.xml +++ b/rma_sale/views/rma_order_line_view.xml @@ -18,6 +18,7 @@ Date: Fri, 18 May 2018 11:19:24 +0200 Subject: [PATCH 26/50] [9.0] rma_sale: add default sale operation --- rma_sale/__manifest__.py | 19 +++++++++++-------- rma_sale/data/rma_operation.xml | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 rma_sale/data/rma_operation.xml diff --git a/rma_sale/__manifest__.py b/rma_sale/__manifest__.py index 32335dbe..6b838049 100644 --- a/rma_sale/__manifest__.py +++ b/rma_sale/__manifest__.py @@ -10,13 +10,16 @@ 'summary': 'Links RMA with Sales Orders', 'author': "Eficent, Odoo Community Association (OCA)", 'website': 'http://www.github.com/OCA/rma', - 'depends': ['rma', 'rma_account', 'sale_stock'], - 'data': ['views/rma_order_view.xml', - 'views/rma_operation_view.xml', - 'views/sale_order_view.xml', - 'wizards/rma_order_line_make_sale_order_view.xml', - 'wizards/rma_add_sale.xml', - 'views/rma_order_line_view.xml'], - 'installable': False, + 'depends': ['rma_account', 'sale_stock'], + 'data': [ + 'data/rma_operation.xml', + 'views/rma_order_view.xml', + 'views/rma_operation_view.xml', + 'views/sale_order_view.xml', + 'wizards/rma_order_line_make_sale_order_view.xml', + 'wizards/rma_add_sale.xml', + 'views/rma_order_line_view.xml', + ], + 'installable': True, 'auto_install': True, } diff --git a/rma_sale/data/rma_operation.xml b/rma_sale/data/rma_operation.xml new file mode 100644 index 00000000..6de28dc8 --- /dev/null +++ b/rma_sale/data/rma_operation.xml @@ -0,0 +1,16 @@ + + + + + Sale after receive + SL-C + received + ordered + no + no + customer + + + + + From ef1f6aa8016e9604d49643e750fddceb0f7834b8 Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Wed, 16 May 2018 16:16:35 +0200 Subject: [PATCH 27/50] [9.0][REW] rma_sale: complete rework of the tests (they didn't make sense at all before) --- rma_sale/tests/__init__.py | 5 +- rma_sale/tests/test_rma.py | 470 ---------------------------- rma_sale/tests/test_rma_dropship.py | 96 ------ rma_sale/tests/test_rma_sale.py | 154 +++++++++ rma_sale/tests/test_supplier_rma.py | 156 --------- 5 files changed, 156 insertions(+), 725 deletions(-) delete mode 100644 rma_sale/tests/test_rma.py delete mode 100644 rma_sale/tests/test_rma_dropship.py create mode 100644 rma_sale/tests/test_rma_sale.py delete mode 100644 rma_sale/tests/test_supplier_rma.py diff --git a/rma_sale/tests/__init__.py b/rma_sale/tests/__init__.py index dfa77946..83ee6fd7 100644 --- a/rma_sale/tests/__init__.py +++ b/rma_sale/tests/__init__.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- # © 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -from . import test_rma -from . import test_supplier_rma -from . import test_rma_dropship + +from . import test_rma_sale diff --git a/rma_sale/tests/test_rma.py b/rma_sale/tests/test_rma.py deleted file mode 100644 index fca5f716..00000000 --- a/rma_sale/tests/test_rma.py +++ /dev/null @@ -1,470 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) - -from openerp.tests import common -from openerp import fields - - -class TestRma(common.TransactionCase): - - """ Test the routes and the quantities """ - - def setUp(self): - super(TestRma, self).setUp() - - self.rma_make_picking = self.env['rma_make_picking.wizard'] - self.make_supplier_rma = self.env["rma.order.line.make.supplier.rma"] - self.rma_add_stock_move = self.env['rma_add_stock_move'] - self.stockpicking = self.env['stock.picking'] - self.rma = self.env['rma.order'] - self.rma_line = self.env['rma.order.line'] - self.rma_op = self.env['rma.operation'] - self.rma_cust_replace_op_id = self.env.ref( - 'rma.rma_operation_customer_replace') - self.rma_sup_replace_op_id = self.env.ref( - 'rma.rma_operation_supplier_replace') - self.product_id = self.env.ref('product.product_product_4') - self.product_1 = self.env.ref('product.product_product_25') - self.product_2 = self.env.ref('product.product_product_7') - self.product_3 = self.env.ref('product.product_product_11') - self.uom_unit = self.env.ref('product.product_uom_unit') - # assign an operation - self.product_1.write( - {'rma_customer_operation_id': self.rma_cust_replace_op_id.id, - 'rma_supplier_operation_id': self.rma_sup_replace_op_id.id}) - self.product_2.write( - {'rma_customer_operation_id': self.rma_cust_replace_op_id.id, - 'rma_supplier_operation_id': self.rma_sup_replace_op_id.id}) - self.product_3.write( - {'rma_customer_operation_id': self.rma_cust_replace_op_id.id, - 'rma_supplier_operation_id': self.rma_sup_replace_op_id.id}) - self.partner_id = self.env.ref('base.res_partner_12') - self.stock_location = self.env.ref('stock.stock_location_stock') - wh = self.env.ref('stock.warehouse0') - self.stock_rma_location = wh.lot_rma_id - self.customer_location = self.env.ref( - 'stock.stock_location_customers') - self.supplier_location = self.env.ref( - 'stock.stock_location_suppliers') - self.product_uom_id = self.env.ref('product.product_uom_unit') - products2move = [(self.product_1, 3), (self.product_2, 5), - (self.product_3, 2)] - self.rma_customer_id = self._create_rma_from_move( - products2move, 'customer', self.env.ref('base.res_partner_2'), - dropship=False) - - def _create_picking(self, partner): - return self.stockpicking.create({ - 'partner_id': partner.id, - 'picking_type_id': self.env.ref('stock.picking_type_in').id, - 'location_id': self.stock_location.id, - 'location_dest_id': self.supplier_location.id - }) - - def _create_rma_from_move(self, products2move, type, partner, dropship, - supplier_address_id=None): - picking_in = self._create_picking(partner) - - moves = [] - if type == 'customer': - for item in products2move: - move_values = self._prepare_move( - item[0], item[1], self.stock_location, - self.customer_location, picking_in) - moves.append(self.env['stock.move'].create(move_values)) - else: - for item in products2move: - move_values = self._prepare_move( - item[0], item[1], self.supplier_location, - self.stock_rma_location, picking_in) - moves.append(self.env['stock.move'].create(move_values)) - # Create the RMA from the stock_move - rma_id = self.rma.create( - { - 'reference': '0001', - 'type': type, - 'partner_id': partner.id, - 'company_id': self.env.ref('base.main_company').id - }) - for move in moves: - if type == 'customer': - wizard = self.rma_add_stock_move.new( - {'stock_move_id': move.id, 'customer': True, - 'active_ids': rma_id.id, - 'partner_id': move.partner_id.id, - 'active_model': 'rma.order', - } - ) - wizard.with_context({ - 'stock_move_id': move.id, 'customer': True, - 'active_ids': rma_id.id, - 'partner_id': move.partner_id.id, - 'active_model': 'rma.order', - }) - - data = wizard._prepare_rma_line_from_stock_move(move) - data['partner_id'] = move.partner_id.id - wizard.add_lines() - - else: - wizard = self.rma_add_stock_move.new( - {'stock_move_id': move.id, 'supplier': True, - 'active_ids': rma_id.id, - 'partner_id': move.partner_id.id, - 'active_model': 'rma.order', - } - ) - wizard.with_context( - {'stock_move_id': move.id, 'supplier': True, - 'active_ids': rma_id.id, - 'partner_id': move.partner_id.id, - 'active_model': 'rma.order', - }) - - data = wizard._prepare_rma_line_from_stock_move(move) - data['partner_id'] = move.partner_id.id - wizard.add_lines() - if dropship: - data.update(customer_to_supplier=dropship, - supplier_address_id=supplier_address_id.id) - data['partner_id'] = move.partner_id.id - data['rma_id'] = rma_id.id - self.line = self.rma_line.create(data) - # approve the RMA Line - self.rma_line.action_rma_to_approve() - self.line.action_rma_approve() - rma_id._compute_in_shipment_count() - rma_id._compute_out_shipment_count() - rma_id._compute_supplier_line_count() - rma_id._compute_line_count() - rma_id.action_view_in_shipments() - rma_id.action_view_out_shipments() - rma_id.action_view_lines() - - rma_id.partner_id.action_open_partner_rma() - rma_id.partner_id._compute_rma_line_count() - # approve the RMA -# rma_id.action_rma_to_approve() -# rma_id.action_rma_approve() - return rma_id - - def _prepare_move(self, product, qty, src, dest, picking_in): - res = { - 'partner_id': self.partner_id.id, - 'product_id': product.id, - 'name': product.partner_ref, - 'state': 'confirmed', - 'product_uom': self.product_uom_id.id or product.uom_id.id, - 'product_uom_qty': qty, - 'origin': 'Test RMA', - 'location_id': src.id, - 'location_dest_id': dest.id, - 'picking_id': picking_in.id - } - return res - - def test_add_sale(self): - wizard = self.env['rma_add_sale'].with_context({ - 'active_ids': self.rma_customer_id.ids, - 'active_model': 'rma.order', - 'active_id': self.rma_customer_id.id - }).create({'partner_id': self.partner_id.id, - 'rma_id': self.rma_customer_id.id, - 'sale_id': self._create_sale_order().id, - 'sale_line_ids': - [(6, 0, [self._create_sale_order().order_line.id])], - }) - wizard.default_get([str(self._create_sale_order().id), - str(self._create_sale_order().order_line.id), - str(self.partner_id.id)]) - wizard.add_lines() - - for line in self.rma_customer_id.rma_line_ids: - line._compute_qty_to_sell() - line.sale_type = 'ordered' - line._compute_qty_to_sell() - line.sale_type = 'received' - line._compute_qty_to_sell() - line._compute_qty_sold() - line._compute_sales_count() - - data = {'sale_line_id': self._create_sale_order().order_line.id} - new_line = self.rma_line.new(data) - new_line._onchange_sale_line_id() - - line.action_view_sale_order() - self.rma_customer_id.\ - _get_line_domain(self.rma_customer_id, - self.rma_customer_id.rma_line_ids[3]) - self.rma_customer_id._compute_sales_count() - self.rma_customer_id.action_view_sale_order() - - def test_rma_order_line_make_sale_order(self): - - self.rma_sale_order_item =\ - self.env['rma.order.line.make.sale.order.item'] - self.rma_sale_order = self.env['rma.order.line.make.sale.order'] - - self.product_id.income =\ - self.env.ref('account.data_account_type_receivable').id - self.product_id.expense =\ - self.env.ref('account.data_account_type_expenses').id - - sale_order = self.rma_sale_order.with_context({ - 'active_ids': self.rma_customer_id.rma_line_ids.ids, - 'active_model': 'rma.order.line', - 'active_id': 1 - }).create({'sale_order_id': self._create_sale_order().id, - 'partner_id': self.partner_id.id, - }) - self.rma_sale_order_item.create({ - 'line_id': self.rma_customer_id.rma_line_ids[0].id, - 'rma_id': self.rma_customer_id.id, - 'product_id': self.product_id.id, - 'name': 'Test RMA Refund', - 'product_qty': self.rma_customer_id.rma_line_ids[0].product_qty, - 'wiz_id': sale_order.id - }) - for line in sale_order.item_ids: - line.product_qty = self.rma_customer_id.rma_line_ids[0].product_qty - sale_order.make_sale_order() - sale_order.write({'sale_order_id': False}) - sale_order.make_sale_order() - - def test_rma_refund(self): - - self.rma_refund_item = self.env['rma.refund.item'] - self.rma_refund = self.env['rma.refund'] - - self.product_id.income =\ - self.env.ref('account.data_account_type_receivable').id - self.product_id.expense =\ - self.env.ref('account.data_account_type_expenses').id - - self.product_id.product_tmpl_id.categ_id.\ - property_stock_account_input_categ_id =\ - self.env.ref('account.data_account_type_receivable').id - self.product_id.product_tmpl_id.categ_id.\ - property_stock_account_output_categ_id =\ - self.env.ref('account.data_account_type_expenses').id - - for line in self.rma_customer_id.rma_line_ids: - line.refund_policy = 'ordered' - - refund = self.rma_refund.with_context({ - 'active_ids': self.rma_customer_id.rma_line_ids.ids, - 'active_model': 'rma.order.line', - 'active_id': 1 - }).create({'description': 'Test Reason', - 'date_invoice': fields.datetime.now() - }) - self.rma_refund_item.create({ - 'line_id': self.rma_customer_id.rma_line_ids[0].id, - 'rma_id': self.rma_customer_id.id, - 'product_id': self.product_id.id, - 'name': 'Test RMA Refund', - 'product_qty': self.rma_customer_id.rma_line_ids[0].product_qty, - 'wiz_id': refund.id - }) - - def _create_sale_order(self): - self.sale_order_id = self.env['sale.order'].create({ - 'partner_id': self.partner_id.id, - 'partner_invoice_id': self.partner_id.id, - 'partner_shipping_id': self.partner_id.id, - 'order_line': [(0, 0, { - 'name': self.product_id.name, - 'product_id': self.product_id.id, - 'product_uom_qty': - self.rma_customer_id.rma_line_ids[0].product_qty, - 'price_unit': 100.00, - })] - }) - self.env["sale.order.line"].\ - name_search(name=self.product_id.name, operator='ilike', - args=[('id', 'in', self.sale_order_id.order_line.ids)]) - self.env["sale.order.line"].\ - _name_search(name=self.product_id.name, operator='ilike', - args=[('id', 'in', self.sale_order_id.order_line.ids) - ]) - self.sale_order_id.order_line._prepare_order_line_procurement() - return self.sale_order_id - - def test_rma_order_line(self): - for line in self.rma_customer_id.rma_line_ids: - line.with_context({'default_rma_id': line.rma_id.id - })._default_warehouse_id() - line._default_location_id() - line.with_context({'partner_id': line.rma_id.partner_id.id - })._default_delivery_address() - line._compute_in_shipment_count() - line._compute_out_shipment_count() - line._compute_procurement_count() - - data = {'reference_move_id': line.reference_move_id.id} - new_line = self.rma_line.new(data) - new_line._onchange_reference_move_id() - - line.action_rma_to_approve() - line.action_rma_draft() - line.action_rma_done() - - data = {'product_id': line.product_id.id} - new_line = self.rma_line.new(data) - new_line._onchange_product_id() - - data = {'operation_id': line.operation_id.id} - new_line = self.rma_line.new(data) - new_line._onchange_operation_id() - - data = {'customer_to_supplier': line.customer_to_supplier} - new_line = self.rma_line.new(data) - new_line._onchange_receipt_policy() - - data = {'lot_id': line.lot_id.id} - new_line = self.rma_line.new(data) - new_line._onchange_lot_id() - - line.action_view_in_shipments() - line.action_view_out_shipments() - line.action_view_procurements() - - def test_customer_rma(self): - wizard = self.rma_make_picking.with_context({ - 'active_ids': self.rma_customer_id.rma_line_ids.ids, - 'active_model': 'rma.order.line', - 'picking_type': 'incoming', - 'active_id': 1 - }).create({}) - procurements = wizard._create_picking() - group_ids = set([proc.group_id.id for proc in procurements if - proc.group_id]) - domain = [('group_id', 'in', list(group_ids))] - picking = self.stockpicking.search(domain) - self.assertEquals(len(picking), 1, - "Incorrect number of pickings created") - moves = picking.move_lines - self.assertEquals(len(moves), 3, - "Incorrect number of moves created") - for line in self.rma_customer_id.rma_line_ids: - # common qtys for all products - self.assertEquals(line.qty_received, 0, - "Wrong qty received") - self.assertEquals(line.qty_incoming, 0, - "Wrong qty incoming") - self.assertEquals(line.qty_delivered, 0, - "Wrong qty delivered") - # product specific - if line.product_id == self.product_1: - self.assertEquals(line.qty_to_receive, 3, - "Wrong qty to receive") - self.assertEquals(line.qty_incoming, 0, - "Wrong qty incoming") - if line.product_id == self.product_2: - self.assertEquals(line.qty_to_receive, 5, - "Wrong qty to receive") - self.assertEquals(line.qty_incoming, 0, - "Wrong qty incoming") - if line.product_id == self.product_3: - self.assertEquals(line.qty_to_receive, 2, - "Wrong qty to receive") - self.assertEquals(line.qty_incoming, 0, - "Wrong qty incoming") - picking.action_assign() - picking.do_new_transfer() - for line in self.rma_customer_id.rma_line_ids: - self.assertEquals(line.qty_received, 0, - "Wrong qty receive") - self.assertEquals(line.qty_incoming, 0, - "Wrong qty incoming") - self.assertEquals(line.qty_delivered, 0, - "Wrong qty delivered") - if line.product_id == self.product_1: - self.assertEquals(line.qty_received, 0, - "Wrong qty received") - self.assertEquals(line.qty_to_deliver, 3, - "Wrong qty to_deliver") - if line.product_id == self.product_2: - self.assertEquals(line.qty_received, 0, - "Wrong qty received") - self.assertEquals(line.qty_to_deliver, 5, - "Wrong qty to_deliver") - if line.product_id == self.product_3: - self.assertEquals(line.qty_received, 0, - "Wrong qty received") - self.assertEquals(line.qty_to_deliver, 2, - "Wrong qty to_deliver") - - wizard = self.rma_make_picking.with_context({ - 'active_id': 1, - 'active_ids': self.rma_customer_id.rma_line_ids.ids, - 'active_model': 'rma.order.line', - 'picking_type': 'outgoing', - }).create({}) - procurements = wizard._create_picking() - group_ids = set([proc.group_id.id for proc in procurements if - proc.group_id]) - domain = [('group_id', 'in', list(group_ids))] - pickings = self.stockpicking.search(domain) - self.assertEquals(len(pickings), 2, - "Incorrect number of pickings created") - picking_out = pickings[1] - moves = picking_out.move_lines - self.assertEquals(len(moves), 3, - "Incorrect number of moves created") - for line in self.rma_customer_id.rma_line_ids: - self.assertEquals(line.qty_received, 0, - "Wrong qty receive") - self.assertEquals(line.qty_incoming, 0, - "Wrong qty incoming") - self.assertEquals(line.qty_delivered, 0, - "Wrong qty delivered") - if line.product_id == self.product_1: - self.assertEquals(line.qty_to_deliver, 3, - "Wrong qty to deliver") - self.assertEquals(line.qty_outgoing, 6, - "Wrong qty outgoing") - self.assertEquals(line.qty_received, 0, - "Wrong qty received") - if line.product_id == self.product_2: - self.assertEquals(line.qty_received, 0, - "Wrong qty received") - self.assertEquals(line.qty_to_deliver, 5, - "Wrong qty to deliver") - self.assertEquals(line.qty_outgoing, 10, - "Wrong qty outgoing") - if line.product_id == self.product_3: - self.assertEquals(line.qty_received, 0, - "Wrong qty received") - self.assertEquals(line.qty_to_deliver, 2, - "Wrong qty to deliver") - self.assertEquals(line.qty_outgoing, 4, - "Wrong qty outgoing") - picking_out.action_assign() - picking_out.do_new_transfer() - for line in self.rma_customer_id.rma_line_ids: - self.assertEquals(line.qty_received, 0, - "Wrong qty receive") - self.assertEquals(line.qty_incoming, 0, - "Wrong qty incoming") - self.assertEquals(line.qty_delivered, 0, - "Wrong qty deliver") - if line.product_id == self.product_1: - self.assertEquals(line.qty_to_receive, 3, - "Wrong qty to received") - self.assertEquals(line.qty_to_deliver, 3, - "Wrong qty to delivered") - if line.product_id == self.product_2: - self.assertEquals(line.qty_to_receive, 5, - "Wrong qty to received") - self.assertEquals(line.qty_to_deliver, 5, - "Wrong qty to delivered") - if line.product_id == self.product_3: - self.assertEquals(line.qty_to_receive, 2, - "Wrong qty to received") - self.assertEquals(line.qty_to_deliver, 2, - "Wrong qty to delivered") - self.line.action_rma_done() - self.assertEquals(self.line.state, 'done', - "Wrong State") diff --git a/rma_sale/tests/test_rma_dropship.py b/rma_sale/tests/test_rma_dropship.py deleted file mode 100644 index 9c99a538..00000000 --- a/rma_sale/tests/test_rma_dropship.py +++ /dev/null @@ -1,96 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) - -from . import test_rma - - -class TestRmaDropship(test_rma.TestRma): - - def setUp(self): - super(TestRmaDropship, self).setUp() - products2move = [(self.product_1, 3), (self.product_2, 5), - (self.product_3, 2)] - self.rma_droship_id = self._create_rma_from_move( - products2move, 'customer', self.env.ref('base.res_partner_2'), - dropship=True, - supplier_address_id=self.env.ref('base.res_partner_3')) - - def test_dropship(self): - wizard = self.make_supplier_rma.with_context({ - 'active_ids': self.rma_droship_id.rma_line_ids.ids, - 'active_model': 'rma.order.line', - 'active_id': 1 - }).create({}) - res = wizard.make_supplier_rma() - supplier_rma = self.rma.browse(res['res_id']) - for line in supplier_rma.rma_line_ids: - line.action_rma_to_approve() - line.action_rma_approve() - wizard = self.rma_make_picking.with_context({ - 'active_id': 1, - 'active_ids': supplier_rma.rma_line_ids.ids, - 'active_model': 'rma.order.line', - 'picking_type': 'incoming', - }).create({}) - procurements = wizard._create_picking() - group_ids = set([proc.group_id.id for proc in procurements if - proc.group_id]) - domain = [('group_id', 'in', list(group_ids))] - picking = self.stockpicking.search(domain) - self.assertEquals(len(picking), 1, - "Incorrect number of pickings created") - moves = picking.move_lines - self.assertEquals(len(moves), 3, - "Incorrect number of moves created") - for line in supplier_rma.rma_line_ids: - # common qtys for all products - self.assertEquals(line.qty_received, 0, - "Wrong qty received") - self.assertEquals(line.qty_outgoing, 0, - "Wrong qty incoming") - self.assertEquals(line.qty_delivered, 0, - "Wrong qty delivered") - # product specific - if line.product_id == self.product_1: - self.assertEquals(line.qty_to_receive, 3, - "Wrong qty to receive") - self.assertEquals(line.qty_to_deliver, 3, - "Wrong qty to deliver") - self.assertEquals(line.qty_incoming, 3, - "Wrong qty outgoing") - if line.product_id == self.product_2: - self.assertEquals(line.qty_to_receive, 5, - "Wrong qty to receive") - self.assertEquals(line.qty_to_deliver, 5, - "Wrong qty to deliver") - self.assertEquals(line.qty_incoming, 5, - "Wrong qty outgoing") - if line.product_id == self.product_3: - self.assertEquals(line.qty_to_receive, 2, - "Wrong qty to receive") - self.assertEquals(line.qty_to_deliver, 2, - "Wrong qty to deliver") - self.assertEquals(line.qty_incoming, 2, - "Wrong qty outgoing") - - for line in self.rma_droship_id.rma_line_ids: - if line.product_id == self.product_1: - self.assertEquals(line.qty_to_supplier_rma, 0, - "Wrong qty to supplier rma") - self.assertEquals(line.qty_in_supplier_rma, 3, - "Wrong qty in supplier rma") - if line.product_id == self.product_2: - self.assertEquals(line.qty_to_supplier_rma, 0, - "Wrong qty to supplier rma") - self.assertEquals(line.qty_in_supplier_rma, 5, - "Wrong qty in supplier rma") - if line.product_id == self.product_3: - self.assertEquals(line.qty_to_supplier_rma, 0, - "Wrong qty to supplier rma") - self.assertEquals(line.qty_in_supplier_rma, 2, - "Wrong qty in supplier rma") - for line in self.rma_droship_id.rma_line_ids: - line.action_rma_done() - self.assertEquals(line.state, 'done', - "Wrong State") diff --git a/rma_sale/tests/test_rma_sale.py b/rma_sale/tests/test_rma_sale.py new file mode 100644 index 00000000..e4389bae --- /dev/null +++ b/rma_sale/tests/test_rma_sale.py @@ -0,0 +1,154 @@ +# -*- coding: utf-8 -*- +# Copyright 2017-18 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from openerp.tests import common + + +class TestRmaSale(common.SingleTransactionCase): + + @classmethod + def setUpClass(cls): + super(TestRmaSale, cls).setUpClass() + + cls.rma_obj = cls.env['rma.order'] + cls.rma_line_obj = cls.env['rma.order.line'] + cls.rma_op_obj = cls.env['rma.operation'] + cls.rma_add_sale_wiz = cls.env['rma_add_sale'] + cls.rma_make_sale_wiz = cls.env['rma.order.line.make.sale.order'] + cls.so_obj = cls.env['sale.order'] + cls.sol_obj = cls.env['sale.order.line'] + cls.product_obj = cls.env['product.product'] + cls.partner_obj = cls.env['res.partner'] + + cls.rma_route_cust = cls.env.ref('rma.route_rma_customer') + + # Create customer + customer1 = cls.partner_obj.create({'name': 'Customer 1'}) + + # Create products + cls.product_1 = cls.product_obj.create({ + 'name': 'Test Product 1', + 'type': 'product', + 'list_price': 100.0, + }) + cls.product_2 = cls.product_obj.create({ + 'name': 'Test Product 2', + 'type': 'product', + 'list_price': 150.0, + }) + + # Create SO: + cls.so = cls.so_obj.create({ + 'partner_id': customer1.id, + 'partner_invoice_id': customer1.id, + 'partner_shipping_id': customer1.id, + 'order_line': [ + (0, 0, { + 'name': cls.product_1.name, + 'product_id': cls.product_1.id, + 'product_uom_qty': 20.0, + 'product_uom': cls.product_1.uom_id.id, + 'price_unit': cls.product_1.list_price + }), + (0, 0, { + 'name': cls.product_2.name, + 'product_id': cls.product_2.id, + 'product_uom_qty': 18.0, + 'product_uom': cls.product_2.uom_id.id, + 'price_unit': cls.product_2.list_price + }), + ], + 'pricelist_id': cls.env.ref('product.list0').id, + }) + + # Create RMA group and operation: + cls.rma_group = cls.rma_obj.create({ + 'partner_id': customer1.id, + }) + cls.operation_1 = cls.rma_op_obj.create({ + 'code': 'TEST', + 'name': 'Sale afer receive', + 'type': 'customer', + 'receipt_policy': 'ordered', + 'sale_policy': 'received', + 'in_route_id': cls.rma_route_cust.id, + 'out_route_id': cls.rma_route_cust.id, + }) + cls.operation_2 = cls.rma_op_obj.create({ + 'code': 'TEST', + 'name': 'Receive and Sale', + 'type': 'customer', + 'receipt_policy': 'ordered', + 'sale_policy': 'ordered', + 'in_route_id': cls.rma_route_cust.id, + 'out_route_id': cls.rma_route_cust.id, + }) + + def test_01_add_from_sale_order(self): + """Test wizard to create RMA from Sales Orders.""" + add_sale = self.rma_add_sale_wiz.with_context({ + 'customer': True, + 'active_ids': self.rma_group.id, + 'active_model': 'rma.order', + }).create({ + 'sale_id': self.so.id, + 'sale_line_ids': [(6, 0, self.so.order_line.ids)], + }) + add_sale.add_lines() + self.assertEqual(len(self.rma_group.rma_line_ids), 2) + + def test_02_rma_sale_operation(self): + """Test RMA quantities using sale operations.""" + # Received sale_policy: + rma_1 = self.rma_group.rma_line_ids.filtered( + lambda r: r.product_id == self.product_1) + rma_1.write({ + 'operation_id': self.operation_1.id, + }) + rma_1._onchange_operation_id() + self.assertEqual(rma_1.sale_policy, 'received') + self.assertEqual(rma_1.qty_to_sell, 0.0) + # TODO: receive and check qty_to_sell is 20.0 + # Ordered sale_policy: + rma_2 = self.rma_group.rma_line_ids.filtered( + lambda r: r.product_id == self.product_2) + rma_2.write({ + 'operation_id': self.operation_2.id, + }) + rma_2._onchange_operation_id() + self.assertEqual(rma_2.sale_policy, 'ordered') + self.assertEqual(rma_2.qty_to_sell, 18.0) + + def test_03_rma_create_sale(self): + """Generate a Sales Order from a customer RMA.""" + rma = self.rma_group.rma_line_ids.filtered( + lambda r: r.product_id == self.product_2) + self.assertEqual(rma.sales_count, 0) + self.assertEqual(rma.qty_to_sell, 18.0) + self.assertEqual(rma.qty_sold, 0.0) + make_sale = self.rma_make_sale_wiz.with_context({ + 'customer': True, + 'active_ids': rma.id, + 'active_model': 'rma.order.line', + }).create({ + 'partner_id': rma.partner_id.id, + }) + make_sale.make_sale_order() + self.assertEqual(rma.sales_count, 1) + rma.sale_line_ids.order_id.action_confirm() + self.assertEqual(rma.qty_to_sell, 0.0) + self.assertEqual(rma.qty_sold, 18.0) + + def test_04_fill_rma_from_so_line(self): + """Test filling a RMA (line) from a Sales Order line.""" + so_line = self.so.order_line.filtered( + lambda r: r.product_id == self.product_1) + rma = self.rma_line_obj.new({ + 'partner_id': self.so.partner_id.id, + 'sale_line_id': so_line.id, + }) + self.assertFalse(rma.product_id) + rma._onchange_sale_line_id() + self.assertEqual(rma.product_id, self.product_1) + self.assertEqual(rma.product_qty, 20.0) diff --git a/rma_sale/tests/test_supplier_rma.py b/rma_sale/tests/test_supplier_rma.py deleted file mode 100644 index 64a1e1ff..00000000 --- a/rma_sale/tests/test_supplier_rma.py +++ /dev/null @@ -1,156 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) - -from . import test_rma - - -class TestSupplierRma(test_rma.TestRma): - - def setUp(self): - super(TestSupplierRma, self).setUp() - products2move = [(self.product_1, 3), (self.product_2, 5), - (self.product_3, 2)] - self.rma_supplier_id = self._create_rma_from_move( - products2move, 'supplier', self.env.ref('base.res_partner_1'), - dropship=False) - - def test_supplier_rma(self): - wizard = self.rma_make_picking.with_context({ - 'active_ids': self.rma_supplier_id.rma_line_ids.ids, - 'active_model': 'rma.order.line', - 'picking_type': 'outgoing', - 'active_id': 1 - }).create({}) - procurements = wizard._create_picking() - group_ids = set([proc.group_id.id for proc in procurements if - proc.group_id]) - domain = [('group_id', 'in', list(group_ids))] - picking = self.stockpicking.search(domain) - self.assertEquals(len(picking), 1, - "Incorrect number of pickings created") - moves = picking.move_lines - self.assertEquals(len(moves), 3, - "Incorrect number of moves created") - for line in self.rma_supplier_id.rma_line_ids: - # common qtys for all products - self.assertEquals(line.qty_received, 0, - "Wrong qty received") - self.assertEquals(line.qty_incoming, 0, - "Wrong qty incoming") - self.assertEquals(line.qty_delivered, 0, - "Wrong qty delivered") - # product specific - if line.product_id == self.product_1: - self.assertEquals(line.qty_to_receive, 3, - "Wrong qty to receive") - self.assertEquals(line.qty_to_deliver, 3, - "Wrong qty to deliver") - self.assertEquals(line.qty_outgoing, 3, - "Wrong qty outgoing") - if line.product_id == self.product_2: - self.assertEquals(line.qty_to_receive, 5, - "Wrong qty to receive") - self.assertEquals(line.qty_to_deliver, 5, - "Wrong qty to deliver") - self.assertEquals(line.qty_outgoing, 5, - "Wrong qty outgoing") - if line.product_id == self.product_3: - self.assertEquals(line.qty_to_receive, 2, - "Wrong qty to receive") - self.assertEquals(line.qty_to_deliver, 2, - "Wrong qty to deliver") - self.assertEquals(line.qty_outgoing, 2, - "Wrong qty outgoing") - - picking.action_assign() - picking.do_transfer() - for line in self.rma_supplier_id.rma_line_ids: - self.assertEquals(line.qty_incoming, 0, - "Wrong qty incoming") - self.assertEquals(line.qty_received, 0, - "Wrong qty received") - if line.product_id == self.product_1: - self.assertEquals(line.qty_delivered, 3, - "Wrong qty delivered") - self.assertEquals(line.qty_to_receive, 3, - "Wrong qty to receive") - if line.product_id == self.product_2: - self.assertEquals(line.qty_delivered, 5, - "Wrong qty delivered") - self.assertEquals(line.qty_to_receive, 5, - "Wrong qty to receive") - if line.product_id == self.product_3: - self.assertEquals(line.qty_delivered, 2, - "Wrong qty delivered") - self.assertEquals(line.qty_to_receive, 2, - "Wrong qty to receive") - wizard = self.rma_make_picking.with_context({ - 'active_id': 1, - 'active_ids': self.rma_supplier_id.rma_line_ids.ids, - 'active_model': 'rma.order.line', - 'picking_type': 'incoming', - }).create({}) - procurements = wizard._create_picking() - group_ids = set([proc.group_id.id for proc in procurements if - proc.group_id]) - domain = [('group_id', 'in', list(group_ids))] - pickings = self.stockpicking.search(domain) - self.assertEquals(len(pickings), 2, - "Incorrect number of pickings created") - picking_out = pickings[1] - moves = picking_out.move_lines - self.assertEquals(len(moves), 3, - "Incorrect number of moves created") - for line in self.rma_supplier_id.rma_line_ids: - self.assertEquals(line.qty_incoming, 0, - "Wrong qty incoming") - self.assertEquals(line.qty_received, 0, - "Wrong qty received") - if line.product_id == self.product_1: - self.assertEquals(line.qty_to_receive, 3, - "Wrong qty to receive") - self.assertEquals(line.qty_incoming, 0, - "Wrong qty incoming") - self.assertEquals(line.qty_delivered, 3, - "Wrong qty delivered") - if line.product_id == self.product_2: - self.assertEquals(line.qty_to_receive, 5, - "Wrong qty to receive") - self.assertEquals(line.qty_delivered, 5, - "Wrong qty deliver") - if line.product_id == self.product_3: - self.assertEquals(line.qty_to_receive, 2, - "Wrong qty to receive") - self.assertEquals(line.qty_delivered, 2, - "Wrong qty deliver") - picking_out.action_assign() - picking_out.do_transfer() - for line in self.rma_supplier_id.rma_line_ids[0]: - self.assertEquals(line.qty_to_receive, 3, - "Wrong qty to receive") - self.assertEquals(line.qty_incoming, 0, - "Wrong qty incoming") - self.assertEquals(line.qty_received, 0, - "Wrong qty receive") - self.assertEquals(line.qty_outgoing, 0, - "Wrong qty outgoing") - if line.product_id == self.product_1: - self.assertEquals(line.qty_received, 0, - "Wrong qty received") - self.assertEquals(line.qty_delivered, 6, - "Wrong qty delivered") - if line.product_id == self.product_2: - self.assertEquals(line.qty_received, 0, - "Wrong qty received") - self.assertEquals(line.qty_delivered, 10, - "Wrong qty delivered") - if line.product_id == self.product_3: - self.assertEquals(line.qty_received, 0, - "Wrong qty received") - self.assertEquals(line.qty_delivered, 4, - "Wrong qty delivered") - for line in self.rma_supplier_id.rma_line_ids: - line.action_rma_done() - self.assertEquals(line.state, 'done', - "Wrong State") From 37b2164b5f57744caf8cd9ba879aa771009004f6 Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Thu, 24 May 2018 11:21:38 +0200 Subject: [PATCH 28/50] fixup! fix --- rma_sale/models/rma_order_line.py | 22 ++++++++++++++++++++++ rma_sale/views/rma_order_line_view.xml | 10 +++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/rma_sale/models/rma_order_line.py b/rma_sale/models/rma_order_line.py index f344ffee..da30c3b0 100644 --- a/rma_sale/models/rma_order_line.py +++ b/rma_sale/models/rma_order_line.py @@ -66,6 +66,28 @@ class RmaOrderLine(models.Model): sales_count = fields.Integer( compute=_compute_sales_count, string='# of Sales') + @api.onchange('product_id', 'partner_id') + def _onchange_product_id(self): + """Domain for sale_line_id is computed here to make it dynamic.""" + res = super(RmaOrderLine, self)._onchange_product_id() + if not res.get('domain'): + res['domain'] = {} + domain = [ + '|', + ('order_id.partner_id', '=', self.partner_id.id), + ('order_id.partner_id', 'child_of', self.partner_id.id)] + if self.product_id: + domain.append(('product_id', '=', self.product_id.id)) + res['domain']['sale_line_id'] = domain + return res + + @api.onchange('operation_id') + def _onchange_operation_id(self): + res = super(RmaOrderLine, self)._onchange_operation_id() + if self.operation_id: + self.sale_policy = self.operation_id.sale_policy or 'no' + return res + @api.multi def _prepare_rma_line_from_sale_order_line(self, line): self.ensure_one() diff --git a/rma_sale/views/rma_order_line_view.xml b/rma_sale/views/rma_order_line_view.xml index d3d4199f..c82596de 100644 --- a/rma_sale/views/rma_order_line_view.xml +++ b/rma_sale/views/rma_order_line_view.xml @@ -18,11 +18,7 @@ + options="{'no_create': True}"/> @@ -31,7 +27,7 @@ - + - + From d4d65f7ad008ae5ad798b13735a71ab04571703d Mon Sep 17 00:00:00 2001 From: aaron Date: Thu, 24 May 2018 12:05:51 +0200 Subject: [PATCH 29/50] [FIX]rma_sale sale_policy instead of sale_type --- rma_sale/models/rma_operation.py | 2 +- rma_sale/models/rma_order_line.py | 12 ++++++------ rma_sale/views/rma_operation_view.xml | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/rma_sale/models/rma_operation.py b/rma_sale/models/rma_operation.py index a00f9a8d..8f2ed4e5 100644 --- a/rma_sale/models/rma_operation.py +++ b/rma_sale/models/rma_operation.py @@ -7,7 +7,7 @@ from odoo import fields, models class RmaOperation(models.Model): _inherit = 'rma.operation' - sale_type = fields.Selection([ + sale_policy = fields.Selection([ ('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'), ('received', 'Based on Received Quantities')], string="Sale Policy", default='no') diff --git a/rma_sale/models/rma_order_line.py b/rma_sale/models/rma_order_line.py index da30c3b0..39fafc60 100644 --- a/rma_sale/models/rma_order_line.py +++ b/rma_sale/models/rma_order_line.py @@ -9,23 +9,23 @@ from odoo.addons import decimal_precision as dp class RmaOrderLine(models.Model): _inherit = "rma.order.line" - @api.depends('sale_line_ids', 'sale_type', 'sales_count', + @api.depends('sale_line_ids', 'sale_policy', 'sales_count', 'sale_line_ids.state') @api.multi def _compute_qty_to_sell(self): for rec in self: - if rec.sale_type == 'no': + if rec.sale_policy == 'no': rec.qty_to_sell = 0.0 - elif rec.sale_type == 'ordered': + elif rec.sale_policy == 'ordered': qty = self._get_rma_sold_qty() rec.qty_to_sell = self.product_qty - qty - elif rec.sale_type == 'received': + elif rec.sale_policy == 'received': qty = self._get_rma_sold_qty() rec.qty_to_sell = self.qty_received - qty else: rec.qty_to_sell = 0.0 - @api.depends('sale_line_ids', 'sale_type', 'sales_count', + @api.depends('sale_line_ids', 'sale_policy', 'sales_count', 'sale_line_ids.state') def _compute_qty_sold(self): self.qty_sold = self._get_rma_sold_qty() @@ -59,7 +59,7 @@ class RmaOrderLine(models.Model): digits=dp.get_precision('Product Unit of Measure'), readonly=True, compute=_compute_qty_sold, store=True) - sale_type = fields.Selection(selection=[ + sale_policy = fields.Selection(selection=[ ('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'), ('received', 'Based on Received Quantities')], string="Sale Policy", default='no', required=True) diff --git a/rma_sale/views/rma_operation_view.xml b/rma_sale/views/rma_operation_view.xml index cd97ee1d..7b5664b5 100644 --- a/rma_sale/views/rma_operation_view.xml +++ b/rma_sale/views/rma_operation_view.xml @@ -8,7 +8,7 @@ - + @@ -19,7 +19,7 @@ - + From c14e4e684feed1e569c66c8249fa32eb0b19ac2b Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Thu, 24 May 2018 12:15:50 +0200 Subject: [PATCH 30/50] [9.0] rma: add filters for pending quantities --- rma_sale/views/rma_order_line_view.xml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/rma_sale/views/rma_order_line_view.xml b/rma_sale/views/rma_order_line_view.xml index c82596de..7197bb13 100644 --- a/rma_sale/views/rma_order_line_view.xml +++ b/rma_sale/views/rma_order_line_view.xml @@ -1,6 +1,5 @@ - rma.order.line.form @@ -97,5 +96,17 @@ -
+ + rma.order.line.select - rma_sale + rma.order.line + + + + + + + + + + From fa77250f2548c42a72284c28f020b67df3c5675a Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 25 May 2018 12:39:00 +0200 Subject: [PATCH 31/50] [FIX]when selling use the standard routes not rma ones --- rma_sale/wizards/rma_order_line_make_sale_order.py | 5 ----- 1 file changed, 5 deletions(-) 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 dee5fb73..cb958eb4 100644 --- a/rma_sale/wizards/rma_order_line_make_sale_order.py +++ b/rma_sale/wizards/rma_order_line_make_sale_order.py @@ -30,7 +30,6 @@ class RmaLineMakeSaleOrder(models.TransientModel): 'product_qty': line.qty_to_sell, 'rma_id': line.rma_id.id, 'out_warehouse_id': line.out_warehouse_id.id, - 'out_route_id': line.out_route_id.id, 'product_uom_id': line.uom_id.id, } @@ -82,7 +81,6 @@ class RmaLineMakeSaleOrder(models.TransientModel): 'order_id': so.id, 'product_id': product.id, 'product_uom': product.uom_po_id.id, - 'route_id': item.out_route_id.id, 'product_uom_qty': item.product_qty, 'rma_line_id': item.line_id.id } @@ -148,6 +146,3 @@ 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') - out_route_id = fields.Many2one( - comodel_name='stock.location.route', string='Outbound Route', - domain=[('rma_selectable', '=', True)]) From d848eacf061cfac8bf192619dca1960f7deffb75 Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 25 May 2018 16:15:20 +0200 Subject: [PATCH 32/50] [FIX]sale group --- rma_sale/views/rma_order_line_view.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rma_sale/views/rma_order_line_view.xml b/rma_sale/views/rma_order_line_view.xml index 7197bb13..e714231b 100644 --- a/rma_sale/views/rma_order_line_view.xml +++ b/rma_sale/views/rma_order_line_view.xml @@ -10,7 +10,7 @@ @@ -49,7 +49,7 @@ From 16f3d7a7a06d14e54da7cd193ada1ddcd82e780c Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 25 May 2018 16:48:50 +0200 Subject: [PATCH 33/50] [IMP]name get when filling form sale order lines --- rma_sale/models/sale_order_line.py | 4 +++- rma_sale/views/rma_order_line_view.xml | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/rma_sale/models/sale_order_line.py b/rma_sale/models/sale_order_line.py index 84041190..1fa38d98 100644 --- a/rma_sale/models/sale_order_line.py +++ b/rma_sale/models/sale_order_line.py @@ -33,8 +33,10 @@ class SaleOrderLine(models.Model): if self.env.context.get('rma'): for sale in self: if sale.order_id.name: - res.append((sale.id, "%s %s qty:%s" % ( + res.append((sale.id, "%s %s, %s qty:%s" % ( sale.order_id.name, + " ".join(str(x) for x in [ + inv.number for inv in sale.order_id.invoice_ids]), sale.product_id.name, sale.product_uom_qty))) else: res.append(super(SaleOrderLine, sale).name_get()[0]) diff --git a/rma_sale/views/rma_order_line_view.xml b/rma_sale/views/rma_order_line_view.xml index e714231b..8412cf7c 100644 --- a/rma_sale/views/rma_order_line_view.xml +++ b/rma_sale/views/rma_order_line_view.xml @@ -17,6 +17,7 @@ From e2f674c19f229de6c2ed7bd96c0e021217f6a7a0 Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Fri, 25 May 2018 10:45:31 +0200 Subject: [PATCH 34/50] [9.0] rma_sale: add advanced refund operation --- rma_sale/data/rma_operation.xml | 12 ++++++++++++ rma_sale/models/rma_order_line.py | 18 ++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/rma_sale/data/rma_operation.xml b/rma_sale/data/rma_operation.xml index 6de28dc8..b0fcfd39 100644 --- a/rma_sale/data/rma_operation.xml +++ b/rma_sale/data/rma_operation.xml @@ -13,4 +13,16 @@ + + Advanced Refund + AR-C + received + ordered + no + received + customer + + + + diff --git a/rma_sale/models/rma_order_line.py b/rma_sale/models/rma_order_line.py index 39fafc60..ef72c913 100644 --- a/rma_sale/models/rma_order_line.py +++ b/rma_sale/models/rma_order_line.py @@ -10,25 +10,23 @@ class RmaOrderLine(models.Model): _inherit = "rma.order.line" @api.depends('sale_line_ids', 'sale_policy', 'sales_count', - 'sale_line_ids.state') - @api.multi + 'sale_line_ids.state', 'qty_received', 'product_qty') def _compute_qty_to_sell(self): for rec in self: - if rec.sale_policy == 'no': - rec.qty_to_sell = 0.0 - elif rec.sale_policy == 'ordered': - qty = self._get_rma_sold_qty() - rec.qty_to_sell = self.product_qty - qty + if rec.sale_policy == 'ordered': + qty = rec._get_rma_sold_qty() + rec.qty_to_sell = rec.product_qty - qty elif rec.sale_policy == 'received': - qty = self._get_rma_sold_qty() - rec.qty_to_sell = self.qty_received - qty + qty = rec._get_rma_sold_qty() + rec.qty_to_sell = rec.qty_received - qty else: rec.qty_to_sell = 0.0 @api.depends('sale_line_ids', 'sale_policy', 'sales_count', 'sale_line_ids.state') def _compute_qty_sold(self): - self.qty_sold = self._get_rma_sold_qty() + for rec in self: + rec.qty_sold = rec._get_rma_sold_qty() @api.multi def _compute_sales_count(self): From 0b8434a6eeee8cf5d5943c1b210c6ea2262559ce Mon Sep 17 00:00:00 2001 From: aaron Date: Thu, 31 May 2018 10:34:43 +0200 Subject: [PATCH 35/50] [IMP]nicer name_get in sale_order_line --- rma_sale/models/sale_order_line.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/rma_sale/models/sale_order_line.py b/rma_sale/models/sale_order_line.py index 1fa38d98..2b8c1551 100644 --- a/rma_sale/models/sale_order_line.py +++ b/rma_sale/models/sale_order_line.py @@ -33,11 +33,13 @@ class SaleOrderLine(models.Model): if self.env.context.get('rma'): for sale in self: if sale.order_id.name: - res.append((sale.id, "%s %s, %s qty:%s" % ( - sale.order_id.name, - " ".join(str(x) for x in [ - inv.number for inv in sale.order_id.invoice_ids]), - sale.product_id.name, sale.product_uom_qty))) + res.append( + (sale.id, "SO:%s | INV: %s, | PART:%s | QTY:%s" % ( + sale.order_id.name, + " ".join(str(x) for x in [ + inv.number + for inv in sale.order_id.invoice_ids]), + sale.product_id.name, sale.product_uom_qty))) else: res.append(super(SaleOrderLine, sale).name_get()[0]) return res From f71900de3271749da8c9af5e213a19317674c061 Mon Sep 17 00:00:00 2001 From: aaron Date: Thu, 28 Jun 2018 11:41:14 +0200 Subject: [PATCH 36/50] [IMP]update module version --- rma_sale/__manifest__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rma_sale/__manifest__.py b/rma_sale/__manifest__.py index 6b838049..ae8c06ba 100644 --- a/rma_sale/__manifest__.py +++ b/rma_sale/__manifest__.py @@ -4,7 +4,7 @@ { 'name': 'RMA Sale', - 'version': '10.0.1.0.0', + 'version': '10.0.2.0.0', 'license': 'LGPL-3', 'category': 'RMA', 'summary': 'Links RMA with Sales Orders', From 25cbf1bc1cd6d24b41b744a4c2a503e6783acd62 Mon Sep 17 00:00:00 2001 From: aheficent Date: Wed, 22 Aug 2018 13:36:20 +0200 Subject: [PATCH 37/50] [MIG]rma_sale to v11 --- rma_sale/__init__.py | 3 +-- rma_sale/__manifest__.py | 5 ++--- rma_sale/models/__init__.py | 3 +-- rma_sale/models/rma_operation.py | 3 +-- rma_sale/models/rma_order.py | 3 +-- rma_sale/models/rma_order_line.py | 3 +-- rma_sale/models/sale_order_line.py | 4 +--- rma_sale/tests/__init__.py | 3 +-- rma_sale/tests/test_rma_sale.py | 3 +-- rma_sale/wizards/__init__.py | 3 +-- rma_sale/wizards/rma_add_sale.py | 3 +-- rma_sale/wizards/rma_make_picking.py | 3 +-- .../wizards/rma_order_line_make_sale_order.py | 17 +++++++---------- .../rma_order_line_make_sale_order_view.xml | 19 ++++--------------- rma_sale/wizards/rma_refund.py | 3 +-- 15 files changed, 25 insertions(+), 53 deletions(-) diff --git a/rma_sale/__init__.py b/rma_sale/__init__.py index 4105ff51..44815ecb 100644 --- a/rma_sale/__init__.py +++ b/rma_sale/__init__.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from . import models from . import wizards diff --git a/rma_sale/__manifest__.py b/rma_sale/__manifest__.py index ae8c06ba..19cee716 100644 --- a/rma_sale/__manifest__.py +++ b/rma_sale/__manifest__.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) { 'name': 'RMA Sale', - 'version': '10.0.2.0.0', + 'version': '11.0.1.0.0', 'license': 'LGPL-3', 'category': 'RMA', 'summary': 'Links RMA with Sales Orders', diff --git a/rma_sale/models/__init__.py b/rma_sale/models/__init__.py index 0ec7edb9..6108253c 100644 --- a/rma_sale/models/__init__.py +++ b/rma_sale/models/__init__.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from . import sale_order_line from . import rma_order_line diff --git a/rma_sale/models/rma_operation.py b/rma_sale/models/rma_operation.py index 8f2ed4e5..14e086f8 100644 --- a/rma_sale/models/rma_operation.py +++ b/rma_sale/models/rma_operation.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import fields, models diff --git a/rma_sale/models/rma_order.py b/rma_sale/models/rma_order.py index 952bcbcc..db4d6a7a 100644 --- a/rma_sale/models/rma_order.py +++ b/rma_sale/models/rma_order.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import api, fields, models diff --git a/rma_sale/models/rma_order_line.py b/rma_sale/models/rma_order_line.py index ef72c913..078e57e1 100644 --- a/rma_sale/models/rma_order_line.py +++ b/rma_sale/models/rma_order_line.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import api, fields, models, _ from odoo.exceptions import ValidationError diff --git a/rma_sale/models/sale_order_line.py b/rma_sale/models/sale_order_line.py index 2b8c1551..645fc4fa 100644 --- a/rma_sale/models/sale_order_line.py +++ b/rma_sale/models/sale_order_line.py @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) - from odoo import api, fields, models diff --git a/rma_sale/tests/__init__.py b/rma_sale/tests/__init__.py index 83ee6fd7..fae781a4 100644 --- a/rma_sale/tests/__init__.py +++ b/rma_sale/tests/__init__.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from . import test_rma_sale diff --git a/rma_sale/tests/test_rma_sale.py b/rma_sale/tests/test_rma_sale.py index e4389bae..5cc3096d 100644 --- a/rma_sale/tests/test_rma_sale.py +++ b/rma_sale/tests/test_rma_sale.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# Copyright 2017-18 Eficent Business and IT Consulting Services S.L. +# Copyright 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from openerp.tests import common diff --git a/rma_sale/wizards/__init__.py b/rma_sale/wizards/__init__.py index 40e8ecb8..631e0330 100644 --- a/rma_sale/wizards/__init__.py +++ b/rma_sale/wizards/__init__.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from . import rma_order_line_make_sale_order diff --git a/rma_sale/wizards/rma_add_sale.py b/rma_sale/wizards/rma_add_sale.py index de4ce988..0946b082 100644 --- a/rma_sale/wizards/rma_add_sale.py +++ b/rma_sale/wizards/rma_add_sale.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import _, api, fields, models diff --git a/rma_sale/wizards/rma_make_picking.py b/rma_sale/wizards/rma_make_picking.py index 85ec2f71..32011807 100644 --- a/rma_sale/wizards/rma_make_picking.py +++ b/rma_sale/wizards/rma_make_picking.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import api, fields, models 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 cb958eb4..b16760c2 100644 --- a/rma_sale/wizards/rma_order_line_make_sale_order.py +++ b/rma_sale/wizards/rma_order_line_make_sale_order.py @@ -1,6 +1,5 @@ -# -*- coding: utf-8 -*- -# Copyright 2016 Eficent Business and IT Consulting Services S.L. -# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0). +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) import odoo.addons.decimal_precision as dp from odoo import _, api, exceptions, fields, models @@ -129,20 +128,18 @@ class RmaLineMakeSaleOrderItem(models.TransientModel): _description = "RMA Line Make Sale Order Item" wiz_id = fields.Many2one( - comodel_name='rma.order.line.make.sale.order', string='Wizard', - required=True, readonly=True) + comodel_name='rma.order.line.make.sale.order', string='Wizard') line_id = fields.Many2one( - comodel_name='rma.order.line', string='RMA Line', required=True) + comodel_name='rma.order.line', string='RMA Line') rma_id = fields.Many2one( - comodel_name='rma.order', related='line_id.rma_id', - string='RMA Order', readonly=True) + comodel_name='rma.order', related='line_id.rma_id') product_id = fields.Many2one( comodel_name='product.product', string='Product') - name = fields.Char(string='Description', required=True, readonly=True) + name = fields.Char(string='Description') product_qty = fields.Float( string='Quantity to sell', digits=dp.get_precision('Product UoS')) product_uom_id = fields.Many2one( - comodel_name='product.uom', string='UoM', readonly=True) + comodel_name='product.uom', string='UoM') out_warehouse_id = fields.Many2one( comodel_name='stock.warehouse', string='Outbound Warehouse') free_of_charge = fields.Boolean(string='Free of Charge') 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 395e6275..308e6e7c 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 @@ -13,8 +13,8 @@ /> + domain="[('partner_id','=', partner_id)]" + context="{'partner_id': partner_id}"/> - - +
@@ -60,16 +59,6 @@ new - - - Create RFQ - client_action_multi - - action - rma.order.line - -
diff --git a/rma_sale/wizards/rma_refund.py b/rma_sale/wizards/rma_refund.py index 7ab7d032..2240b3f9 100644 --- a/rma_sale/wizards/rma_refund.py +++ b/rma_sale/wizards/rma_refund.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import api, fields, models From 47bcf3d9f19034cc6f3b60ef76eb894005ce3391 Mon Sep 17 00:00:00 2001 From: aheficent Date: Tue, 2 Oct 2018 12:10:58 +0200 Subject: [PATCH 38/50] [FIX]rma_line view in the sale order line --- rma_sale/views/sale_order_view.xml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/rma_sale/views/sale_order_view.xml b/rma_sale/views/sale_order_view.xml index 2bfe7ca4..cbde25ce 100644 --- a/rma_sale/views/sale_order_view.xml +++ b/rma_sale/views/sale_order_view.xml @@ -7,13 +7,11 @@ - - - + expr="//notebook/page/field[@name='order_line']/form/group/group/field[@name='price_unit']" + position="after"> + From 6a30649edd8b19ed635ed706ba062de83ea0a3aa Mon Sep 17 00:00:00 2001 From: aheficent Date: Thu, 4 Oct 2018 16:27:11 +0200 Subject: [PATCH 39/50] [FIX]currency_id was not filled --- rma_sale/models/rma_order_line.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rma_sale/models/rma_order_line.py b/rma_sale/models/rma_order_line.py index 078e57e1..e06691e0 100644 --- a/rma_sale/models/rma_order_line.py +++ b/rma_sale/models/rma_order_line.py @@ -123,6 +123,7 @@ class RmaOrderLine(models.Model): 'in_route_id': operation.in_route_id.id or route.id, 'out_route_id': operation.out_route_id.id or route.id, 'receipt_policy': operation.receipt_policy, + 'currency_id': line.currency_id.id, 'location_id': (operation.location_id.id or operation.in_warehouse_id.lot_rma_id.id or warehouse.lot_rma_id.id), From 7c03d96015898fcfe8cd025835eca40383cb1e5f Mon Sep 17 00:00:00 2001 From: aheficent Date: Mon, 3 Dec 2018 17:37:49 +0100 Subject: [PATCH 40/50] [FIX]rma_sale. sale_policy only editable in draft --- rma_sale/models/rma_order_line.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rma_sale/models/rma_order_line.py b/rma_sale/models/rma_order_line.py index e06691e0..34039f0e 100644 --- a/rma_sale/models/rma_order_line.py +++ b/rma_sale/models/rma_order_line.py @@ -59,7 +59,8 @@ class RmaOrderLine(models.Model): sale_policy = fields.Selection(selection=[ ('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'), ('received', 'Based on Received Quantities')], - string="Sale Policy", default='no', required=True) + string="Sale Policy", default='no', required=True, + readonly=True, states={'draft': [('readonly', False)]}) sales_count = fields.Integer( compute=_compute_sales_count, string='# of Sales') From d6e7e85a5461a49cba4702919ef180d706edc227 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Tue, 12 Mar 2019 17:59:40 +0100 Subject: [PATCH 41/50] [MIG] rma_sale: Migration to 12.0 --- rma_sale/__manifest__.py | 2 +- rma_sale/models/rma_order.py | 5 +++-- rma_sale/models/rma_order_line.py | 9 ++++----- rma_sale/views/rma_operation_view.xml | 2 -- rma_sale/views/rma_order_line_view.xml | 4 ++-- rma_sale/views/rma_order_view.xml | 4 +--- rma_sale/views/sale_order_view.xml | 2 -- rma_sale/wizards/rma_add_sale.xml | 2 +- rma_sale/wizards/rma_order_line_make_sale_order.py | 4 ++-- rma_sale/wizards/rma_order_line_make_sale_order_view.xml | 9 ++++----- 10 files changed, 18 insertions(+), 25 deletions(-) diff --git a/rma_sale/__manifest__.py b/rma_sale/__manifest__.py index 19cee716..4d107f8d 100644 --- a/rma_sale/__manifest__.py +++ b/rma_sale/__manifest__.py @@ -3,7 +3,7 @@ { 'name': 'RMA Sale', - 'version': '11.0.1.0.0', + 'version': '12.0.1.0.0', 'license': 'LGPL-3', 'category': 'RMA', 'summary': 'Links RMA with Sales Orders', diff --git a/rma_sale/models/rma_order.py b/rma_sale/models/rma_order.py index db4d6a7a..f5236329 100644 --- a/rma_sale/models/rma_order.py +++ b/rma_sale/models/rma_order.py @@ -6,14 +6,15 @@ from odoo import api, fields, models class RmaOrder(models.Model): _inherit = "rma.order" - @api.multi + @api.depends('rma_line_ids', 'rma_line_ids.sale_line_id', + 'rma_line_ids.sale_line_id.order_id') def _compute_sales_count(self): for rma in self: sales = rma.mapped('rma_line_ids.sale_line_id.order_id') rma.sale_count = len(sales) sale_count = fields.Integer( - compute=_compute_sales_count, string='# of Sales') + compute='_compute_sales_count', string='# of Sales') @api.model def _get_line_domain(self, rma_id, line): diff --git a/rma_sale/models/rma_order_line.py b/rma_sale/models/rma_order_line.py index 34039f0e..d4745bd8 100644 --- a/rma_sale/models/rma_order_line.py +++ b/rma_sale/models/rma_order_line.py @@ -27,7 +27,7 @@ class RmaOrderLine(models.Model): for rec in self: rec.qty_sold = rec._get_rma_sold_qty() - @api.multi + @api.depends('sale_line_ids', 'sale_line_ids.order_id') def _compute_sales_count(self): for line in self: sales = line.mapped('sale_line_ids.order_id') @@ -40,7 +40,6 @@ class RmaOrderLine(models.Model): ) sale_id = fields.Many2one( string="Source Sales Order", related='sale_line_id.order_id', - readonly=True, ) sale_line_ids = fields.One2many( comodel_name='sale.order.line', inverse_name='rma_line_id', @@ -49,12 +48,12 @@ class RmaOrderLine(models.Model): qty_to_sell = fields.Float( string='Qty To Sell', copy=False, digits=dp.get_precision('Product Unit of Measure'), - readonly=True, compute=_compute_qty_to_sell, + readonly=True, compute='_compute_qty_to_sell', store=True) qty_sold = fields.Float( string='Qty Sold', copy=False, digits=dp.get_precision('Product Unit of Measure'), - readonly=True, compute=_compute_qty_sold, + readonly=True, compute='_compute_qty_sold', store=True) sale_policy = fields.Selection(selection=[ ('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'), @@ -62,7 +61,7 @@ class RmaOrderLine(models.Model): string="Sale Policy", default='no', required=True, readonly=True, states={'draft': [('readonly', False)]}) sales_count = fields.Integer( - compute=_compute_sales_count, string='# of Sales') + compute='_compute_sales_count', string='# of Sales') @api.onchange('product_id', 'partner_id') def _onchange_product_id(self): diff --git a/rma_sale/views/rma_operation_view.xml b/rma_sale/views/rma_operation_view.xml index 7b5664b5..4ab4a56d 100644 --- a/rma_sale/views/rma_operation_view.xml +++ b/rma_sale/views/rma_operation_view.xml @@ -1,6 +1,5 @@ - rma.operation.tree @@ -24,5 +23,4 @@ - diff --git a/rma_sale/views/rma_order_line_view.xml b/rma_sale/views/rma_order_line_view.xml index 8412cf7c..c6d0f5e5 100644 --- a/rma_sale/views/rma_order_line_view.xml +++ b/rma_sale/views/rma_order_line_view.xml @@ -103,8 +103,8 @@ - - + + diff --git a/rma_sale/views/rma_order_view.xml b/rma_sale/views/rma_order_view.xml index 48ff6f61..f3fd9c47 100644 --- a/rma_sale/views/rma_order_view.xml +++ b/rma_sale/views/rma_order_view.xml @@ -1,6 +1,5 @@ - rma.order.form rma.order @@ -10,12 +9,11 @@ - diff --git a/rma_sale/views/sale_order_view.xml b/rma_sale/views/sale_order_view.xml index cbde25ce..f45b0852 100644 --- a/rma_sale/views/sale_order_view.xml +++ b/rma_sale/views/sale_order_view.xml @@ -1,6 +1,5 @@ - sale.order.form sale.order @@ -15,5 +14,4 @@ - diff --git a/rma_sale/wizards/rma_add_sale.xml b/rma_sale/wizards/rma_add_sale.xml index dd91f0dc..1f0bd4d8 100644 --- a/rma_sale/wizards/rma_add_sale.xml +++ b/rma_sale/wizards/rma_add_sale.xml @@ -32,7 +32,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 b16760c2..b5577c81 100644 --- a/rma_sale/wizards/rma_order_line_make_sale_order.py +++ b/rma_sale/wizards/rma_order_line_make_sale_order.py @@ -132,14 +132,14 @@ class RmaLineMakeSaleOrderItem(models.TransientModel): line_id = fields.Many2one( comodel_name='rma.order.line', string='RMA Line') rma_id = fields.Many2one( - comodel_name='rma.order', related='line_id.rma_id') + comodel_name='rma.order', related='line_id.rma_id', readonly=False) product_id = fields.Many2one( comodel_name='product.product', string='Product') name = fields.Char(string='Description') product_qty = fields.Float( string='Quantity to sell', digits=dp.get_precision('Product UoS')) product_uom_id = fields.Many2one( - comodel_name='product.uom', string='UoM') + comodel_name='uom.uom', string='UoM') out_warehouse_id = fields.Many2one( comodel_name='stock.warehouse', string='Outbound Warehouse') free_of_charge = fields.Boolean(string='Free of Charge') 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 308e6e7c..78052ca1 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 @@ -1,8 +1,8 @@ - - + + RMA Line Make Sale Order rma.order.line.make.sale.order @@ -33,7 +33,7 @@ + groups="uom.group_uom"/> @@ -59,6 +59,5 @@ new - - + From 4a49960825c1891f539e2c046333687fa8599cab Mon Sep 17 00:00:00 2001 From: Bhavesh Odedra Date: Fri, 24 May 2019 13:28:54 +0530 Subject: [PATCH 42/50] [SET] Correct website URL for RMA modules --- rma_sale/__manifest__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rma_sale/__manifest__.py b/rma_sale/__manifest__.py index 4d107f8d..2ecb3bb7 100644 --- a/rma_sale/__manifest__.py +++ b/rma_sale/__manifest__.py @@ -8,7 +8,7 @@ 'category': 'RMA', 'summary': 'Links RMA with Sales Orders', 'author': "Eficent, Odoo Community Association (OCA)", - 'website': 'http://www.github.com/OCA/rma', + 'website': 'https://github.com/Eficent/stock-rma', 'depends': ['rma_account', 'sale_stock'], 'data': [ 'data/rma_operation.xml', From 9b015be4bc1cf55158f4909d0782193b7ec74c36 Mon Sep 17 00:00:00 2001 From: mreficent Date: Wed, 30 Oct 2019 19:38:23 +0100 Subject: [PATCH 43/50] [FIX] tests --- rma_sale/tests/test_rma_sale.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rma_sale/tests/test_rma_sale.py b/rma_sale/tests/test_rma_sale.py index 5cc3096d..f0474cbe 100644 --- a/rma_sale/tests/test_rma_sale.py +++ b/rma_sale/tests/test_rma_sale.py @@ -1,7 +1,7 @@ # Copyright 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -from openerp.tests import common +from odoo.tests import common class TestRmaSale(common.SingleTransactionCase): From c8e8417be16f0747ffa4a5d6335da07075956bb9 Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Tue, 29 Oct 2019 16:37:58 +0100 Subject: [PATCH 44/50] [FIX]remove autoinstall for rma_account, rma_sale and rma_purchase modules --- rma_sale/__manifest__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/rma_sale/__manifest__.py b/rma_sale/__manifest__.py index 2ecb3bb7..d7ed5105 100644 --- a/rma_sale/__manifest__.py +++ b/rma_sale/__manifest__.py @@ -20,5 +20,4 @@ 'views/rma_order_line_view.xml', ], 'installable': True, - 'auto_install': True, } From dfcaa77448aaa4fc2fb89e84d58cc91c9aac1e00 Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Fri, 29 Nov 2019 16:58:14 +0100 Subject: [PATCH 45/50] [FIX] rma_sale --- .../wizards/rma_order_line_make_sale_order.py | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) 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 b5577c81..76fbfa97 100644 --- a/rma_sale/wizards/rma_order_line_make_sale_order.py +++ b/rma_sale/wizards/rma_order_line_make_sale_order.py @@ -23,7 +23,6 @@ class RmaLineMakeSaleOrder(models.TransientModel): def _prepare_item(self, line): return { 'line_id': line.id, - 'rma_line_id': line.id, 'product_id': line.product_id.id, 'name': line.product_id.name, 'product_qty': line.qty_to_sell, @@ -59,13 +58,13 @@ class RmaLineMakeSaleOrder(models.TransientModel): return res @api.model - def _prepare_sale_order(self, out_warehouse, company): + def _prepare_sale_order(self, out_warehouse, company, item): if not self.partner_id: raise exceptions.Warning( _('Enter a customer.')) customer = self.partner_id data = { - 'origin': '', + 'origin': item.line_id.name, 'partner_id': customer.id, 'warehouse_id': out_warehouse.id, 'company_id': company.id, @@ -103,24 +102,20 @@ 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) + po_data = self._prepare_sale_order( + line.out_warehouse_id, + line.company_id, + item) sale = sale_obj.create(po_data) so_line_data = self._prepare_sale_order_line(sale, item) so_line_obj.create(so_line_data) res.append(sale.id) - return { - 'domain': "[('id','in', ["+','.join(map(str, res))+"])]", - 'name': _('Quotations'), - 'view_type': 'form', - 'view_mode': 'tree,form', - 'res_model': 'sale.order', - 'view_id': False, - 'context': False, - 'type': 'ir.actions.act_window' - } + action = self.env.ref('sale.action_orders') + result = action.read()[0] + result['domain'] = "[('id','in', ["+','.join(map(str, res))+"])]" + return result class RmaLineMakeSaleOrderItem(models.TransientModel): From af0573afee5398be4007e33ac925f70fd5289410 Mon Sep 17 00:00:00 2001 From: mreficent Date: Fri, 29 Nov 2019 18:30:43 +0100 Subject: [PATCH 46/50] [FIX] default_gets: avoid using shadowname 'fields' --- rma_sale/wizards/rma_add_sale.py | 4 ++-- rma_sale/wizards/rma_order_line_make_sale_order.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rma_sale/wizards/rma_add_sale.py b/rma_sale/wizards/rma_add_sale.py index 0946b082..306d61f8 100644 --- a/rma_sale/wizards/rma_add_sale.py +++ b/rma_sale/wizards/rma_add_sale.py @@ -10,8 +10,8 @@ class RmaAddSale(models.TransientModel): _description = 'Wizard to add rma lines from SO lines' @api.model - def default_get(self, fields): - res = super(RmaAddSale, self).default_get(fields) + def default_get(self, fields_list): + res = super(RmaAddSale, self).default_get(fields_list) rma_obj = self.env['rma.order'] rma_id = self.env.context['active_ids'] or [] active_model = self.env.context['active_model'] 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 76fbfa97..0cba6c9f 100644 --- a/rma_sale/wizards/rma_order_line_make_sale_order.py +++ b/rma_sale/wizards/rma_order_line_make_sale_order.py @@ -32,9 +32,9 @@ class RmaLineMakeSaleOrder(models.TransientModel): } @api.model - def default_get(self, fields): + def default_get(self, fields_list): res = super(RmaLineMakeSaleOrder, self).default_get( - fields) + fields_list) rma_line_obj = self.env['rma.order.line'] rma_line_ids = self.env.context['active_ids'] or [] active_model = self.env.context['active_model'] From 473758f93a4ded78c2643968e10f40f32d16f098 Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Mon, 9 Mar 2020 11:16:16 +0100 Subject: [PATCH 47/50] [IMP] : black, isort --- rma_sale/__manifest__.py | 34 +-- rma_sale/models/rma_operation.py | 15 +- rma_sale/models/rma_order.py | 26 ++- rma_sale/models/rma_order_line.py | 211 ++++++++++-------- rma_sale/models/sale_order_line.py | 60 +++-- rma_sale/tests/test_rma_sale.py | 195 ++++++++-------- rma_sale/wizards/rma_add_sale.py | 125 ++++++----- rma_sale/wizards/rma_make_picking.py | 9 +- .../wizards/rma_order_line_make_sale_order.py | 129 ++++++----- .../rma_order_line_make_sale_order_view.xml | 1 - rma_sale/wizards/rma_refund.py | 7 +- 11 files changed, 450 insertions(+), 362 deletions(-) diff --git a/rma_sale/__manifest__.py b/rma_sale/__manifest__.py index d7ed5105..12ecabfe 100644 --- a/rma_sale/__manifest__.py +++ b/rma_sale/__manifest__.py @@ -2,22 +2,22 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) { - 'name': 'RMA Sale', - 'version': '12.0.1.0.0', - 'license': 'LGPL-3', - 'category': 'RMA', - 'summary': 'Links RMA with Sales Orders', - 'author': "Eficent, Odoo Community Association (OCA)", - 'website': 'https://github.com/Eficent/stock-rma', - 'depends': ['rma_account', 'sale_stock'], - 'data': [ - 'data/rma_operation.xml', - 'views/rma_order_view.xml', - 'views/rma_operation_view.xml', - 'views/sale_order_view.xml', - 'wizards/rma_order_line_make_sale_order_view.xml', - 'wizards/rma_add_sale.xml', - 'views/rma_order_line_view.xml', + "name": "RMA Sale", + "version": "12.0.1.0.0", + "license": "LGPL-3", + "category": "RMA", + "summary": "Links RMA with Sales Orders", + "author": "Eficent, Odoo Community Association (OCA)", + "website": "https://github.com/Eficent/stock-rma", + "depends": ["rma_account", "sale_stock"], + "data": [ + "data/rma_operation.xml", + "views/rma_order_view.xml", + "views/rma_operation_view.xml", + "views/sale_order_view.xml", + "wizards/rma_order_line_make_sale_order_view.xml", + "wizards/rma_add_sale.xml", + "views/rma_order_line_view.xml", ], - 'installable': True, + "installable": True, } diff --git a/rma_sale/models/rma_operation.py b/rma_sale/models/rma_operation.py index 14e086f8..b981bc02 100644 --- a/rma_sale/models/rma_operation.py +++ b/rma_sale/models/rma_operation.py @@ -4,9 +4,14 @@ from odoo import fields, models class RmaOperation(models.Model): - _inherit = 'rma.operation' + _inherit = "rma.operation" - sale_policy = fields.Selection([ - ('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'), - ('received', 'Based on Received Quantities')], - string="Sale Policy", default='no') + sale_policy = fields.Selection( + [ + ("no", "Not required"), + ("ordered", "Based on Ordered Quantities"), + ("received", "Based on Received Quantities"), + ], + string="Sale Policy", + default="no", + ) diff --git a/rma_sale/models/rma_order.py b/rma_sale/models/rma_order.py index f5236329..383f93b4 100644 --- a/rma_sale/models/rma_order.py +++ b/rma_sale/models/rma_order.py @@ -6,30 +6,34 @@ from odoo import api, fields, models class RmaOrder(models.Model): _inherit = "rma.order" - @api.depends('rma_line_ids', 'rma_line_ids.sale_line_id', - 'rma_line_ids.sale_line_id.order_id') + @api.depends( + "rma_line_ids", + "rma_line_ids.sale_line_id", + "rma_line_ids.sale_line_id.order_id", + ) def _compute_sales_count(self): for rma in self: - sales = rma.mapped('rma_line_ids.sale_line_id.order_id') + sales = rma.mapped("rma_line_ids.sale_line_id.order_id") rma.sale_count = len(sales) - sale_count = fields.Integer( - compute='_compute_sales_count', string='# of Sales') + sale_count = fields.Integer(compute="_compute_sales_count", string="# of Sales") @api.model def _get_line_domain(self, rma_id, line): if line.sale_line_id and line.sale_line_id.id: - domain = [('rma_id', '=', rma_id.id), - ('type', '=', 'supplier'), - ('sale_line_id', '=', line.sale_line_id.id)] + domain = [ + ("rma_id", "=", rma_id.id), + ("type", "=", "supplier"), + ("sale_line_id", "=", line.sale_line_id.id), + ] else: domain = super(RmaOrder, self)._get_line_domain(rma_id, line) return domain @api.multi def action_view_sale_order(self): - action = self.env.ref('sale.action_quotations') + action = self.env.ref("sale.action_quotations") result = action.read()[0] - so_ids = self.mapped('rma_line_ids.sale_line_id.order_id').ids - result['domain'] = [('id', 'in', so_ids)] + so_ids = self.mapped("rma_line_ids.sale_line_id.order_id").ids + result["domain"] = [("id", "in", so_ids)] return result diff --git a/rma_sale/models/rma_order_line.py b/rma_sale/models/rma_order_line.py index d4745bd8..c92d20f8 100644 --- a/rma_sale/models/rma_order_line.py +++ b/rma_sale/models/rma_order_line.py @@ -1,88 +1,114 @@ # Copyright 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -from odoo import api, fields, models, _ +from odoo import _, api, fields, models from odoo.exceptions import ValidationError + from odoo.addons import decimal_precision as dp class RmaOrderLine(models.Model): _inherit = "rma.order.line" - @api.depends('sale_line_ids', 'sale_policy', 'sales_count', - 'sale_line_ids.state', 'qty_received', 'product_qty') + @api.depends( + "sale_line_ids", + "sale_policy", + "sales_count", + "sale_line_ids.state", + "qty_received", + "product_qty", + ) def _compute_qty_to_sell(self): for rec in self: - if rec.sale_policy == 'ordered': + if rec.sale_policy == "ordered": qty = rec._get_rma_sold_qty() rec.qty_to_sell = rec.product_qty - qty - elif rec.sale_policy == 'received': + elif rec.sale_policy == "received": qty = rec._get_rma_sold_qty() rec.qty_to_sell = rec.qty_received - qty else: rec.qty_to_sell = 0.0 - @api.depends('sale_line_ids', 'sale_policy', 'sales_count', - 'sale_line_ids.state') + @api.depends("sale_line_ids", "sale_policy", "sales_count", "sale_line_ids.state") def _compute_qty_sold(self): for rec in self: rec.qty_sold = rec._get_rma_sold_qty() - @api.depends('sale_line_ids', 'sale_line_ids.order_id') + @api.depends("sale_line_ids", "sale_line_ids.order_id") def _compute_sales_count(self): for line in self: - sales = line.mapped('sale_line_ids.order_id') + sales = line.mapped("sale_line_ids.order_id") line.sales_count = len(sales) sale_line_id = fields.Many2one( - comodel_name='sale.order.line', string='Originating Sales Order Line', - ondelete='restrict', copy=False, - readonly=True, states={'draft': [('readonly', False)]}, + comodel_name="sale.order.line", + string="Originating Sales Order Line", + ondelete="restrict", + copy=False, + readonly=True, + states={"draft": [("readonly", False)]}, ) sale_id = fields.Many2one( - string="Source Sales Order", related='sale_line_id.order_id', + string="Source Sales Order", related="sale_line_id.order_id" ) sale_line_ids = fields.One2many( - comodel_name='sale.order.line', inverse_name='rma_line_id', - string='Sales Order Lines', readonly=True, - states={'draft': [('readonly', False)]}, copy=False) + comodel_name="sale.order.line", + inverse_name="rma_line_id", + string="Sales Order Lines", + readonly=True, + states={"draft": [("readonly", False)]}, + copy=False, + ) qty_to_sell = fields.Float( - string='Qty To Sell', copy=False, - digits=dp.get_precision('Product Unit of Measure'), - readonly=True, compute='_compute_qty_to_sell', - store=True) + string="Qty To Sell", + copy=False, + digits=dp.get_precision("Product Unit of Measure"), + readonly=True, + compute="_compute_qty_to_sell", + store=True, + ) qty_sold = fields.Float( - string='Qty Sold', copy=False, - digits=dp.get_precision('Product Unit of Measure'), - readonly=True, compute='_compute_qty_sold', - store=True) - sale_policy = fields.Selection(selection=[ - ('no', 'Not required'), ('ordered', 'Based on Ordered Quantities'), - ('received', 'Based on Received Quantities')], - string="Sale Policy", default='no', required=True, - readonly=True, states={'draft': [('readonly', False)]}) - sales_count = fields.Integer( - compute='_compute_sales_count', string='# of Sales') + string="Qty Sold", + copy=False, + digits=dp.get_precision("Product Unit of Measure"), + readonly=True, + compute="_compute_qty_sold", + store=True, + ) + sale_policy = fields.Selection( + selection=[ + ("no", "Not required"), + ("ordered", "Based on Ordered Quantities"), + ("received", "Based on Received Quantities"), + ], + string="Sale Policy", + default="no", + required=True, + readonly=True, + states={"draft": [("readonly", False)]}, + ) + sales_count = fields.Integer(compute="_compute_sales_count", string="# of Sales") - @api.onchange('product_id', 'partner_id') + @api.onchange("product_id", "partner_id") def _onchange_product_id(self): """Domain for sale_line_id is computed here to make it dynamic.""" res = super(RmaOrderLine, self)._onchange_product_id() - if not res.get('domain'): - res['domain'] = {} + if not res.get("domain"): + res["domain"] = {} domain = [ - '|', - ('order_id.partner_id', '=', self.partner_id.id), - ('order_id.partner_id', 'child_of', self.partner_id.id)] + "|", + ("order_id.partner_id", "=", self.partner_id.id), + ("order_id.partner_id", "child_of", self.partner_id.id), + ] if self.product_id: - domain.append(('product_id', '=', self.product_id.id)) - res['domain']['sale_line_id'] = domain + domain.append(("product_id", "=", self.product_id.id)) + res["domain"]["sale_line_id"] = domain return res - @api.onchange('operation_id') + @api.onchange("operation_id") def _onchange_operation_id(self): res = super(RmaOrderLine, self)._onchange_operation_id() if self.operation_id: - self.sale_policy = self.operation_id.sale_policy or 'no' + self.sale_policy = self.operation_id.sale_policy or "no" return res @api.multi @@ -94,80 +120,90 @@ class RmaOrderLine(models.Model): if not operation: operation = line.product_id.categ_id.rma_customer_operation_id if not operation: - operation = self.env['rma.operation'].search( - [('type', '=', self.type)], limit=1) + operation = self.env["rma.operation"].search( + [("type", "=", self.type)], limit=1 + ) if not operation: raise ValidationError(_("Please define an operation first")) if not operation.in_route_id or not operation.out_route_id: - route = self.env['stock.location.route'].search( - [('rma_selectable', '=', True)], limit=1) + 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.company_id.id), - ('lot_rma_id', '!=', False)], limit=1) + warehouse = self.env["stock.warehouse"].search( + [("company_id", "=", self.company_id.id), ("lot_rma_id", "!=", False)], + limit=1, + ) if not warehouse: - raise ValidationError(_( - "Please define a warehouse with a default RMA location.")) + raise ValidationError( + _("Please define a warehouse with a default RMA location.") + ) data = { - 'product_id': line.product_id.id, - 'origin': line.order_id.name, - 'uom_id': line.product_uom.id, - 'operation_id': operation.id, - 'product_qty': line.product_uom_qty, - 'delivery_address_id': line.order_id.partner_id.id, - 'invoice_address_id': line.order_id.partner_id.id, - 'price_unit': line.currency_id.compute( - line.price_unit, line.currency_id, round=False), - 'in_route_id': operation.in_route_id.id or route.id, - 'out_route_id': operation.out_route_id.id or route.id, - 'receipt_policy': operation.receipt_policy, - 'currency_id': line.currency_id.id, - 'location_id': (operation.location_id.id or - operation.in_warehouse_id.lot_rma_id.id or - warehouse.lot_rma_id.id), - 'refund_policy': operation.refund_policy, - 'delivery_policy': operation.delivery_policy, - 'in_warehouse_id': operation.in_warehouse_id.id or warehouse.id, - 'out_warehouse_id': operation.out_warehouse_id.id or warehouse.id, + "product_id": line.product_id.id, + "origin": line.order_id.name, + "uom_id": line.product_uom.id, + "operation_id": operation.id, + "product_qty": line.product_uom_qty, + "delivery_address_id": line.order_id.partner_id.id, + "invoice_address_id": line.order_id.partner_id.id, + "price_unit": line.currency_id.compute( + line.price_unit, line.currency_id, round=False + ), + "in_route_id": operation.in_route_id.id or route.id, + "out_route_id": operation.out_route_id.id or route.id, + "receipt_policy": operation.receipt_policy, + "currency_id": line.currency_id.id, + "location_id": ( + operation.location_id.id + or operation.in_warehouse_id.lot_rma_id.id + or warehouse.lot_rma_id.id + ), + "refund_policy": operation.refund_policy, + "delivery_policy": operation.delivery_policy, + "in_warehouse_id": operation.in_warehouse_id.id or warehouse.id, + "out_warehouse_id": operation.out_warehouse_id.id or warehouse.id, } return data - @api.onchange('sale_line_id') + @api.onchange("sale_line_id") def _onchange_sale_line_id(self): if not self.sale_line_id: return - data = self._prepare_rma_line_from_sale_order_line( - self.sale_line_id) + data = self._prepare_rma_line_from_sale_order_line(self.sale_line_id) self.update(data) - self._remove_other_data_origin('sale_line_id') + self._remove_other_data_origin("sale_line_id") @api.multi def _remove_other_data_origin(self, exception): res = super(RmaOrderLine, self)._remove_other_data_origin(exception) - if not exception == 'sale_line_id': + if not exception == "sale_line_id": self.sale_line_id = False return res @api.multi - @api.constrains('sale_line_id', 'partner_id') + @api.constrains("sale_line_id", "partner_id") def _check_sale_partner(self): for rec in self: - if (rec.sale_line_id and - rec.sale_line_id.order_id.partner_id != rec.partner_id and - rec.sale_line_id.order_id.partner_id.parent_id != - rec.partner_id): - raise ValidationError(_( - "RMA customer and originating sales order line customer " - "doesn't match.")) + if ( + rec.sale_line_id + and rec.sale_line_id.order_id.partner_id != rec.partner_id + and rec.sale_line_id.order_id.partner_id.parent_id != rec.partner_id + ): + raise ValidationError( + _( + "RMA customer and originating sales order line customer " + "doesn't match." + ) + ) @api.multi def action_view_sale_order(self): - action = self.env.ref('sale.action_quotations') + action = self.env.ref("sale.action_quotations") result = action.read()[0] - order_ids = self.mapped('sale_line_ids.order_id').ids - result['domain'] = [('id', 'in', order_ids)] + order_ids = self.mapped("sale_line_ids.order_id").ids + result["domain"] = [("id", "in", order_ids)] return result @api.multi @@ -175,6 +211,7 @@ class RmaOrderLine(models.Model): self.ensure_one() qty = 0.0 for sale_line in self.sale_line_ids.filtered( - lambda p: p.state not in ('draft', 'sent', 'cancel')): + lambda p: p.state not in ("draft", "sent", "cancel") + ): qty += sale_line.product_uom_qty return qty diff --git a/rma_sale/models/sale_order_line.py b/rma_sale/models/sale_order_line.py index 645fc4fa..811521a4 100644 --- a/rma_sale/models/sale_order_line.py +++ b/rma_sale/models/sale_order_line.py @@ -7,37 +7,55 @@ class SaleOrderLine(models.Model): _inherit = "sale.order.line" @api.model - def name_search(self, name='', args=None, operator='ilike', limit=100): + def name_search(self, name="", args=None, operator="ilike", limit=100): """Allows to search by SO reference.""" if not args: args = [] - args += ['|', - (self._rec_name, operator, name), - ('order_id.name', operator, name)] + args += [ + "|", + (self._rec_name, operator, name), + ("order_id.name", operator, name), + ] return super(SaleOrderLine, self).name_search( - name=name, args=args, operator=operator, limit=limit) + name=name, args=args, operator=operator, limit=limit + ) @api.model - def _name_search(self, name='', args=None, operator='ilike', - limit=100, name_get_uid=None): + def _name_search( + self, name="", args=None, operator="ilike", limit=100, name_get_uid=None + ): """Typed text is cleared here for better extensibility.""" return super(SaleOrderLine, self)._name_search( - name='', args=args, operator=operator, limit=limit, - name_get_uid=name_get_uid) + name="", + args=args, + operator=operator, + limit=limit, + name_get_uid=name_get_uid, + ) @api.multi def name_get(self): res = [] - if self.env.context.get('rma'): + if self.env.context.get("rma"): for sale in self: if sale.order_id.name: res.append( - (sale.id, "SO:%s | INV: %s, | PART:%s | QTY:%s" % ( - sale.order_id.name, - " ".join(str(x) for x in [ - inv.number - for inv in sale.order_id.invoice_ids]), - sale.product_id.name, sale.product_uom_qty))) + ( + sale.id, + "SO:%s | INV: %s, | PART:%s | QTY:%s" + % ( + sale.order_id.name, + " ".join( + str(x) + for x in [ + inv.number for inv in sale.order_id.invoice_ids + ] + ), + sale.product_id.name, + sale.product_uom_qty, + ), + ) + ) else: res.append(super(SaleOrderLine, sale).name_get()[0]) return res @@ -45,13 +63,13 @@ class SaleOrderLine(models.Model): return super(SaleOrderLine, self).name_get() rma_line_id = fields.Many2one( - comodel_name='rma.order.line', string='RMA', ondelete='restrict') + comodel_name="rma.order.line", string="RMA", ondelete="restrict" + ) @api.multi def _prepare_order_line_procurement(self, group_id=False): vals = super(SaleOrderLine, self)._prepare_order_line_procurement( - group_id=group_id) - vals.update({ - 'rma_line_id': self.rma_line_id.id - }) + group_id=group_id + ) + vals.update({"rma_line_id": self.rma_line_id.id}) return vals diff --git a/rma_sale/tests/test_rma_sale.py b/rma_sale/tests/test_rma_sale.py index f0474cbe..57a469b8 100644 --- a/rma_sale/tests/test_rma_sale.py +++ b/rma_sale/tests/test_rma_sale.py @@ -5,95 +5,103 @@ from odoo.tests import common class TestRmaSale(common.SingleTransactionCase): - @classmethod def setUpClass(cls): super(TestRmaSale, cls).setUpClass() - cls.rma_obj = cls.env['rma.order'] - cls.rma_line_obj = cls.env['rma.order.line'] - cls.rma_op_obj = cls.env['rma.operation'] - cls.rma_add_sale_wiz = cls.env['rma_add_sale'] - cls.rma_make_sale_wiz = cls.env['rma.order.line.make.sale.order'] - cls.so_obj = cls.env['sale.order'] - cls.sol_obj = cls.env['sale.order.line'] - cls.product_obj = cls.env['product.product'] - cls.partner_obj = cls.env['res.partner'] + cls.rma_obj = cls.env["rma.order"] + cls.rma_line_obj = cls.env["rma.order.line"] + cls.rma_op_obj = cls.env["rma.operation"] + cls.rma_add_sale_wiz = cls.env["rma_add_sale"] + cls.rma_make_sale_wiz = cls.env["rma.order.line.make.sale.order"] + cls.so_obj = cls.env["sale.order"] + cls.sol_obj = cls.env["sale.order.line"] + cls.product_obj = cls.env["product.product"] + cls.partner_obj = cls.env["res.partner"] - cls.rma_route_cust = cls.env.ref('rma.route_rma_customer') + cls.rma_route_cust = cls.env.ref("rma.route_rma_customer") # Create customer - customer1 = cls.partner_obj.create({'name': 'Customer 1'}) + customer1 = cls.partner_obj.create({"name": "Customer 1"}) # Create products - cls.product_1 = cls.product_obj.create({ - 'name': 'Test Product 1', - 'type': 'product', - 'list_price': 100.0, - }) - cls.product_2 = cls.product_obj.create({ - 'name': 'Test Product 2', - 'type': 'product', - 'list_price': 150.0, - }) + cls.product_1 = cls.product_obj.create( + {"name": "Test Product 1", "type": "product", "list_price": 100.0} + ) + cls.product_2 = cls.product_obj.create( + {"name": "Test Product 2", "type": "product", "list_price": 150.0} + ) # Create SO: - cls.so = cls.so_obj.create({ - 'partner_id': customer1.id, - 'partner_invoice_id': customer1.id, - 'partner_shipping_id': customer1.id, - 'order_line': [ - (0, 0, { - 'name': cls.product_1.name, - 'product_id': cls.product_1.id, - 'product_uom_qty': 20.0, - 'product_uom': cls.product_1.uom_id.id, - 'price_unit': cls.product_1.list_price - }), - (0, 0, { - 'name': cls.product_2.name, - 'product_id': cls.product_2.id, - 'product_uom_qty': 18.0, - 'product_uom': cls.product_2.uom_id.id, - 'price_unit': cls.product_2.list_price - }), - ], - 'pricelist_id': cls.env.ref('product.list0').id, - }) + cls.so = cls.so_obj.create( + { + "partner_id": customer1.id, + "partner_invoice_id": customer1.id, + "partner_shipping_id": customer1.id, + "order_line": [ + ( + 0, + 0, + { + "name": cls.product_1.name, + "product_id": cls.product_1.id, + "product_uom_qty": 20.0, + "product_uom": cls.product_1.uom_id.id, + "price_unit": cls.product_1.list_price, + }, + ), + ( + 0, + 0, + { + "name": cls.product_2.name, + "product_id": cls.product_2.id, + "product_uom_qty": 18.0, + "product_uom": cls.product_2.uom_id.id, + "price_unit": cls.product_2.list_price, + }, + ), + ], + "pricelist_id": cls.env.ref("product.list0").id, + } + ) # Create RMA group and operation: - cls.rma_group = cls.rma_obj.create({ - 'partner_id': customer1.id, - }) - cls.operation_1 = cls.rma_op_obj.create({ - 'code': 'TEST', - 'name': 'Sale afer receive', - 'type': 'customer', - 'receipt_policy': 'ordered', - 'sale_policy': 'received', - 'in_route_id': cls.rma_route_cust.id, - 'out_route_id': cls.rma_route_cust.id, - }) - cls.operation_2 = cls.rma_op_obj.create({ - 'code': 'TEST', - 'name': 'Receive and Sale', - 'type': 'customer', - 'receipt_policy': 'ordered', - 'sale_policy': 'ordered', - 'in_route_id': cls.rma_route_cust.id, - 'out_route_id': cls.rma_route_cust.id, - }) + cls.rma_group = cls.rma_obj.create({"partner_id": customer1.id}) + cls.operation_1 = cls.rma_op_obj.create( + { + "code": "TEST", + "name": "Sale afer receive", + "type": "customer", + "receipt_policy": "ordered", + "sale_policy": "received", + "in_route_id": cls.rma_route_cust.id, + "out_route_id": cls.rma_route_cust.id, + } + ) + cls.operation_2 = cls.rma_op_obj.create( + { + "code": "TEST", + "name": "Receive and Sale", + "type": "customer", + "receipt_policy": "ordered", + "sale_policy": "ordered", + "in_route_id": cls.rma_route_cust.id, + "out_route_id": cls.rma_route_cust.id, + } + ) def test_01_add_from_sale_order(self): """Test wizard to create RMA from Sales Orders.""" - add_sale = self.rma_add_sale_wiz.with_context({ - 'customer': True, - 'active_ids': self.rma_group.id, - 'active_model': 'rma.order', - }).create({ - 'sale_id': self.so.id, - 'sale_line_ids': [(6, 0, self.so.order_line.ids)], - }) + add_sale = self.rma_add_sale_wiz.with_context( + { + "customer": True, + "active_ids": self.rma_group.id, + "active_model": "rma.order", + } + ).create( + {"sale_id": self.so.id, "sale_line_ids": [(6, 0, self.so.order_line.ids)]} + ) add_sale.add_lines() self.assertEqual(len(self.rma_group.rma_line_ids), 2) @@ -101,38 +109,33 @@ class TestRmaSale(common.SingleTransactionCase): """Test RMA quantities using sale operations.""" # Received sale_policy: rma_1 = self.rma_group.rma_line_ids.filtered( - lambda r: r.product_id == self.product_1) - rma_1.write({ - 'operation_id': self.operation_1.id, - }) + lambda r: r.product_id == self.product_1 + ) + rma_1.write({"operation_id": self.operation_1.id}) rma_1._onchange_operation_id() - self.assertEqual(rma_1.sale_policy, 'received') + self.assertEqual(rma_1.sale_policy, "received") self.assertEqual(rma_1.qty_to_sell, 0.0) # TODO: receive and check qty_to_sell is 20.0 # Ordered sale_policy: rma_2 = self.rma_group.rma_line_ids.filtered( - lambda r: r.product_id == self.product_2) - rma_2.write({ - 'operation_id': self.operation_2.id, - }) + lambda r: r.product_id == self.product_2 + ) + rma_2.write({"operation_id": self.operation_2.id}) rma_2._onchange_operation_id() - self.assertEqual(rma_2.sale_policy, 'ordered') + self.assertEqual(rma_2.sale_policy, "ordered") self.assertEqual(rma_2.qty_to_sell, 18.0) def test_03_rma_create_sale(self): """Generate a Sales Order from a customer RMA.""" rma = self.rma_group.rma_line_ids.filtered( - lambda r: r.product_id == self.product_2) + lambda r: r.product_id == self.product_2 + ) self.assertEqual(rma.sales_count, 0) self.assertEqual(rma.qty_to_sell, 18.0) self.assertEqual(rma.qty_sold, 0.0) - make_sale = self.rma_make_sale_wiz.with_context({ - 'customer': True, - 'active_ids': rma.id, - 'active_model': 'rma.order.line', - }).create({ - 'partner_id': rma.partner_id.id, - }) + make_sale = self.rma_make_sale_wiz.with_context( + {"customer": True, "active_ids": rma.id, "active_model": "rma.order.line"} + ).create({"partner_id": rma.partner_id.id}) make_sale.make_sale_order() self.assertEqual(rma.sales_count, 1) rma.sale_line_ids.order_id.action_confirm() @@ -141,12 +144,10 @@ class TestRmaSale(common.SingleTransactionCase): def test_04_fill_rma_from_so_line(self): """Test filling a RMA (line) from a Sales Order line.""" - so_line = self.so.order_line.filtered( - lambda r: r.product_id == self.product_1) - rma = self.rma_line_obj.new({ - 'partner_id': self.so.partner_id.id, - 'sale_line_id': so_line.id, - }) + so_line = self.so.order_line.filtered(lambda r: r.product_id == self.product_1) + rma = self.rma_line_obj.new( + {"partner_id": self.so.partner_id.id, "sale_line_id": so_line.id} + ) self.assertFalse(rma.product_id) rma._onchange_sale_line_id() self.assertEqual(rma.product_id, self.product_1) diff --git a/rma_sale/wizards/rma_add_sale.py b/rma_sale/wizards/rma_add_sale.py index 306d61f8..d8198640 100644 --- a/rma_sale/wizards/rma_add_sale.py +++ b/rma_sale/wizards/rma_add_sale.py @@ -6,90 +6,105 @@ from odoo.exceptions import ValidationError class RmaAddSale(models.TransientModel): - _name = 'rma_add_sale' - _description = 'Wizard to add rma lines from SO lines' + _name = "rma_add_sale" + _description = "Wizard to add rma lines from SO lines" @api.model def default_get(self, fields_list): res = super(RmaAddSale, self).default_get(fields_list) - rma_obj = self.env['rma.order'] - rma_id = self.env.context['active_ids'] or [] - active_model = self.env.context['active_model'] + rma_obj = self.env["rma.order"] + rma_id = self.env.context["active_ids"] or [] + active_model = self.env.context["active_model"] if not rma_id: return res - assert active_model == 'rma.order', 'Bad context propagation' + assert active_model == "rma.order", "Bad context propagation" rma = rma_obj.browse(rma_id) - res['rma_id'] = rma.id - res['partner_id'] = rma.partner_id.id - res['sale_id'] = False - res['sale_line_ids'] = False + res["rma_id"] = rma.id + res["partner_id"] = rma.partner_id.id + res["sale_id"] = False + res["sale_line_ids"] = False return res rma_id = fields.Many2one( - comodel_name='rma.order', string='RMA Order', readonly=True) - partner_id = fields.Many2one(comodel_name='res.partner', string='Partner', - readonly=True) - sale_id = fields.Many2one(comodel_name='sale.order', string='Order') - sale_line_ids = fields.Many2many('sale.order.line', - 'rma_add_sale_add_line_rel', - 'sale_line_id', 'rma_add_sale_id', - readonly=False, - string='Sale Lines') + comodel_name="rma.order", string="RMA Order", readonly=True + ) + partner_id = fields.Many2one( + comodel_name="res.partner", string="Partner", readonly=True + ) + sale_id = fields.Many2one(comodel_name="sale.order", string="Order") + sale_line_ids = fields.Many2many( + "sale.order.line", + "rma_add_sale_add_line_rel", + "sale_line_id", + "rma_add_sale_id", + readonly=False, + string="Sale Lines", + ) def _prepare_rma_line_from_sale_order_line(self, line): operation = line.product_id.rma_customer_operation_id if not operation: operation = line.product_id.categ_id.rma_customer_operation_id if not operation: - operation = self.env['rma.operation'].search( - [('type', '=', self.rma_id.type)], limit=1) + operation = self.env["rma.operation"].search( + [("type", "=", self.rma_id.type)], limit=1 + ) if not operation: raise ValidationError(_("Please define an operation first")) if not operation.in_route_id or not operation.out_route_id: - route = self.env['stock.location.route'].search( - [('rma_selectable', '=', True)], limit=1) + 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) + 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.")) + raise ValidationError( + _("Please define a warehouse with a " "default rma location.") + ) data = { - 'partner_id': self.partner_id.id, - 'sale_line_id': line.id, - 'product_id': line.product_id.id, - 'origin': line.order_id.name, - 'uom_id': line.product_uom.id, - 'operation_id': operation.id, - 'product_qty': line.product_uom_qty, - 'delivery_address_id': self.sale_id.partner_id.id, - 'invoice_address_id': self.sale_id.partner_id.id, - 'price_unit': line.currency_id.compute( - line.price_unit, line.currency_id, round=False), - 'rma_id': self.rma_id.id, - 'in_route_id': operation.in_route_id.id or route.id, - 'out_route_id': operation.out_route_id.id or route.id, - 'receipt_policy': operation.receipt_policy, - 'location_id': (operation.location_id.id or - operation.in_warehouse_id.lot_rma_id.id or - warehouse.lot_rma_id.id), - 'refund_policy': operation.refund_policy, - 'delivery_policy': operation.delivery_policy, - 'in_warehouse_id': operation.in_warehouse_id.id or warehouse.id, - 'out_warehouse_id': operation.out_warehouse_id.id or warehouse.id, + "partner_id": self.partner_id.id, + "sale_line_id": line.id, + "product_id": line.product_id.id, + "origin": line.order_id.name, + "uom_id": line.product_uom.id, + "operation_id": operation.id, + "product_qty": line.product_uom_qty, + "delivery_address_id": self.sale_id.partner_id.id, + "invoice_address_id": self.sale_id.partner_id.id, + "price_unit": line.currency_id.compute( + line.price_unit, line.currency_id, round=False + ), + "rma_id": self.rma_id.id, + "in_route_id": operation.in_route_id.id or route.id, + "out_route_id": operation.out_route_id.id or route.id, + "receipt_policy": operation.receipt_policy, + "location_id": ( + operation.location_id.id + or operation.in_warehouse_id.lot_rma_id.id + or warehouse.lot_rma_id.id + ), + "refund_policy": operation.refund_policy, + "delivery_policy": operation.delivery_policy, + "in_warehouse_id": operation.in_warehouse_id.id or warehouse.id, + "out_warehouse_id": operation.out_warehouse_id.id or warehouse.id, } return data @api.model def _get_rma_data(self): data = { - 'date_rma': fields.Datetime.now(), - 'delivery_address_id': self.sale_id.partner_id.id, - 'invoice_address_id': self.sale_id.partner_id.id + "date_rma": fields.Datetime.now(), + "delivery_address_id": self.sale_id.partner_id.id, + "invoice_address_id": self.sale_id.partner_id.id, } return data @@ -102,7 +117,7 @@ class RmaAddSale(models.TransientModel): @api.multi def add_lines(self): - rma_line_obj = self.env['rma.order.line'] + rma_line_obj = self.env["rma.order.line"] existing_sale_lines = self._get_existing_sale_lines() for line in self.sale_line_ids: # Load a PO line only once @@ -112,4 +127,4 @@ class RmaAddSale(models.TransientModel): rma = self.rma_id data_rma = self._get_rma_data() rma.write(data_rma) - return {'type': 'ir.actions.act_window_close'} + return {"type": "ir.actions.act_window_close"} diff --git a/rma_sale/wizards/rma_make_picking.py b/rma_sale/wizards/rma_make_picking.py index 32011807..e05bdd13 100644 --- a/rma_sale/wizards/rma_make_picking.py +++ b/rma_sale/wizards/rma_make_picking.py @@ -4,17 +4,16 @@ from odoo import api, fields, models class RmaMakePicking(models.TransientModel): - _inherit = 'rma_make_picking.wizard' + _inherit = "rma_make_picking.wizard" - @api.returns('rma.order.line') + @api.returns("rma.order.line") def _prepare_item(self, line): res = super(RmaMakePicking, self)._prepare_item(line) - res['sale_line_id'] = line.sale_line_id.id + res["sale_line_id"] = line.sale_line_id.id return res class RmaMakePickingItem(models.TransientModel): _inherit = "rma_make_picking.wizard.item" - sale_line_id = fields.Many2one( - comodel_name='sale.order.line', string='Sale Line') + sale_line_id = fields.Many2one(comodel_name="sale.order.line", string="Sale Line") 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..84859c06 100644 --- a/rma_sale/wizards/rma_order_line_make_sale_order.py +++ b/rma_sale/wizards/rma_order_line_make_sale_order.py @@ -1,120 +1,128 @@ # Copyright 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -import odoo.addons.decimal_precision as dp from odoo import _, api, exceptions, fields, models +import odoo.addons.decimal_precision as dp + class RmaLineMakeSaleOrder(models.TransientModel): _name = "rma.order.line.make.sale.order" _description = "Make Sales Order from RMA Line" partner_id = fields.Many2one( - comodel_name='res.partner', string='Customer', required=False, - domain=[('customer', '=', True)]) + comodel_name="res.partner", + string="Customer", + required=False, + domain=[("customer", "=", True)], + ) item_ids = fields.One2many( - comodel_name='rma.order.line.make.sale.order.item', - inverse_name='wiz_id', string='Items') + comodel_name="rma.order.line.make.sale.order.item", + inverse_name="wiz_id", + string="Items", + ) sale_order_id = fields.Many2one( - comodel_name='sale.order', string='Sales Order', required=False, - domain=[('state', '=', 'draft')]) + comodel_name="sale.order", + string="Sales Order", + required=False, + domain=[("state", "=", "draft")], + ) @api.model def _prepare_item(self, line): return { - 'line_id': line.id, - 'product_id': line.product_id.id, - 'name': line.product_id.name, - 'product_qty': line.qty_to_sell, - 'rma_id': line.rma_id.id, - 'out_warehouse_id': line.out_warehouse_id.id, - 'product_uom_id': line.uom_id.id, + "line_id": line.id, + "product_id": line.product_id.id, + "name": line.product_id.name, + "product_qty": line.qty_to_sell, + "rma_id": line.rma_id.id, + "out_warehouse_id": line.out_warehouse_id.id, + "product_uom_id": line.uom_id.id, } @api.model def default_get(self, fields_list): - res = super(RmaLineMakeSaleOrder, self).default_get( - fields_list) - rma_line_obj = self.env['rma.order.line'] - rma_line_ids = self.env.context['active_ids'] or [] - active_model = self.env.context['active_model'] + res = super(RmaLineMakeSaleOrder, self).default_get(fields_list) + rma_line_obj = self.env["rma.order.line"] + rma_line_ids = self.env.context["active_ids"] or [] + active_model = self.env.context["active_model"] if not rma_line_ids: return res - assert active_model == 'rma.order.line', 'Bad context propagation' + assert active_model == "rma.order.line", "Bad context propagation" items = [] lines = rma_line_obj.browse(rma_line_ids) for line in lines: items.append([0, 0, self._prepare_item(line)]) - customers = lines.mapped('partner_id') + customers = lines.mapped("partner_id") if len(customers) == 1: - res['partner_id'] = customers.id + res["partner_id"] = customers.id else: raise exceptions.Warning( - _('Only RMA lines from the same partner can be processed at ' - 'the same time')) - res['item_ids'] = items + _( + "Only RMA lines from the same partner can be processed at " + "the same time" + ) + ) + res["item_ids"] = items return res @api.model def _prepare_sale_order(self, out_warehouse, company, item): if not self.partner_id: - raise exceptions.Warning( - _('Enter a customer.')) + raise exceptions.Warning(_("Enter a customer.")) customer = self.partner_id data = { - 'origin': item.line_id.name, - 'partner_id': customer.id, - 'warehouse_id': out_warehouse.id, - 'company_id': company.id, - } + "origin": item.line_id.name, + "partner_id": customer.id, + "warehouse_id": out_warehouse.id, + "company_id": company.id, + } return data @api.model def _prepare_sale_order_line(self, so, item): product = item.product_id vals = { - 'name': product.name, - 'order_id': so.id, - 'product_id': product.id, - 'product_uom': product.uom_po_id.id, - 'product_uom_qty': item.product_qty, - 'rma_line_id': item.line_id.id + "name": product.name, + "order_id": so.id, + "product_id": product.id, + "product_uom": product.uom_po_id.id, + "product_uom_qty": item.product_qty, + "rma_line_id": item.line_id.id, } if item.free_of_charge: - vals['price_unit'] = 0.0 + vals["price_unit"] = 0.0 return vals @api.multi def make_sale_order(self): res = [] - sale_obj = self.env['sale.order'] - so_line_obj = self.env['sale.order.line'] + sale_obj = self.env["sale.order"] + so_line_obj = self.env["sale.order.line"] sale = False for item in self.item_ids: line = item.line_id if item.product_qty <= 0.0: - raise exceptions.Warning( - _('Enter a positive quantity.')) + raise exceptions.Warning(_("Enter a positive quantity.")) 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) + line.out_warehouse_id, line.company_id, item + ) sale = sale_obj.create(po_data) so_line_data = self._prepare_sale_order_line(sale, item) so_line_obj.create(so_line_data) res.append(sale.id) - action = self.env.ref('sale.action_orders') + action = self.env.ref("sale.action_orders") result = action.read()[0] - result['domain'] = "[('id','in', ["+','.join(map(str, res))+"])]" + result["domain"] = "[('id','in', [" + ",".join(map(str, res)) + "])]" return result @@ -123,18 +131,19 @@ class RmaLineMakeSaleOrderItem(models.TransientModel): _description = "RMA Line Make Sale Order Item" 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.make.sale.order", string="Wizard" + ) + line_id = fields.Many2one(comodel_name="rma.order.line", string="RMA Line") rma_id = fields.Many2one( - comodel_name='rma.order', related='line_id.rma_id', readonly=False) - product_id = fields.Many2one( - comodel_name='product.product', string='Product') - name = fields.Char(string='Description') + comodel_name="rma.order", related="line_id.rma_id", readonly=False + ) + product_id = fields.Many2one(comodel_name="product.product", string="Product") + name = fields.Char(string="Description") product_qty = fields.Float( - string='Quantity to sell', digits=dp.get_precision('Product UoS')) - product_uom_id = fields.Many2one( - comodel_name='uom.uom', string='UoM') + string="Quantity to sell", digits=dp.get_precision("Product UoS") + ) + product_uom_id = fields.Many2one(comodel_name="uom.uom", string="UoM") out_warehouse_id = fields.Many2one( - comodel_name='stock.warehouse', string='Outbound Warehouse') - free_of_charge = fields.Boolean(string='Free of Charge') + comodel_name="stock.warehouse", string="Outbound Warehouse" + ) + free_of_charge = fields.Boolean(string="Free of Charge") 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..065059a6 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 @@ -60,4 +60,3 @@ - diff --git a/rma_sale/wizards/rma_refund.py b/rma_sale/wizards/rma_refund.py index 2240b3f9..26e2a855 100644 --- a/rma_sale/wizards/rma_refund.py +++ b/rma_sale/wizards/rma_refund.py @@ -6,10 +6,10 @@ from odoo import api, fields, models class RmaRefund(models.TransientModel): _inherit = "rma.refund" - @api.returns('rma.order.line') + @api.returns("rma.order.line") def _prepare_item(self, line): res = super(RmaRefund, self)._prepare_item(line) - res['sale_line_id'] = line.sale_line_id.id + res["sale_line_id"] = line.sale_line_id.id return res @@ -17,4 +17,5 @@ class RmaRefundItem(models.TransientModel): _inherit = "rma.refund.item" sale_line_id = fields.Many2one( - comodel_name='sale.order.line', string='Sale Order Line') + comodel_name="sale.order.line", string="Sale Order Line" + ) From 68a43b8bf053adab6f2f215ecd8cae5e5524965c Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Mon, 9 Mar 2020 11:23:53 +0100 Subject: [PATCH 48/50] [MIG]rma_sale v13 --- rma_sale/__init__.py | 2 +- rma_sale/__manifest__.py | 6 +++--- rma_sale/models/__init__.py | 2 +- rma_sale/models/rma_operation.py | 2 +- rma_sale/models/rma_order.py | 3 +-- rma_sale/models/rma_order_line.py | 21 ++++++++----------- rma_sale/models/sale_order_line.py | 4 +--- rma_sale/tests/__init__.py | 2 +- rma_sale/tests/test_rma_sale.py | 2 +- rma_sale/wizards/__init__.py | 2 +- rma_sale/wizards/rma_add_sale.py | 16 +++++++------- rma_sale/wizards/rma_add_sale.xml | 2 -- rma_sale/wizards/rma_make_picking.py | 2 +- .../wizards/rma_order_line_make_sale_order.py | 9 ++------ .../rma_order_line_make_sale_order_view.xml | 1 - rma_sale/wizards/rma_refund.py | 2 +- 16 files changed, 31 insertions(+), 47 deletions(-) diff --git a/rma_sale/__init__.py b/rma_sale/__init__.py index 44815ecb..41d70b8d 100644 --- a/rma_sale/__init__.py +++ b/rma_sale/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2020 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from . import models from . import wizards diff --git a/rma_sale/__manifest__.py b/rma_sale/__manifest__.py index 12ecabfe..565a729f 100644 --- a/rma_sale/__manifest__.py +++ b/rma_sale/__manifest__.py @@ -1,13 +1,13 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2020 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) { "name": "RMA Sale", - "version": "12.0.1.0.0", + "version": "13.0.1.0.0", "license": "LGPL-3", "category": "RMA", "summary": "Links RMA with Sales Orders", - "author": "Eficent, Odoo Community Association (OCA)", + "author": "ForgeFlow, Odoo Community Association (OCA)", "website": "https://github.com/Eficent/stock-rma", "depends": ["rma_account", "sale_stock"], "data": [ diff --git a/rma_sale/models/__init__.py b/rma_sale/models/__init__.py index 6108253c..c0f8b897 100644 --- a/rma_sale/models/__init__.py +++ b/rma_sale/models/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2020 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from . import sale_order_line from . import rma_order_line diff --git a/rma_sale/models/rma_operation.py b/rma_sale/models/rma_operation.py index b981bc02..00c886c7 100644 --- a/rma_sale/models/rma_operation.py +++ b/rma_sale/models/rma_operation.py @@ -1,4 +1,4 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2020 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import fields, models diff --git a/rma_sale/models/rma_order.py b/rma_sale/models/rma_order.py index 383f93b4..4de2e614 100644 --- a/rma_sale/models/rma_order.py +++ b/rma_sale/models/rma_order.py @@ -1,4 +1,4 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2020 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import api, fields, models @@ -30,7 +30,6 @@ class RmaOrder(models.Model): domain = super(RmaOrder, self)._get_line_domain(rma_id, line) return domain - @api.multi def action_view_sale_order(self): action = self.env.ref("sale.action_quotations") result = action.read()[0] diff --git a/rma_sale/models/rma_order_line.py b/rma_sale/models/rma_order_line.py index c92d20f8..caf332d7 100644 --- a/rma_sale/models/rma_order_line.py +++ b/rma_sale/models/rma_order_line.py @@ -1,10 +1,8 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2020 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import _, api, fields, models from odoo.exceptions import ValidationError -from odoo.addons import decimal_precision as dp - class RmaOrderLine(models.Model): _inherit = "rma.order.line" @@ -61,7 +59,7 @@ class RmaOrderLine(models.Model): qty_to_sell = fields.Float( string="Qty To Sell", copy=False, - digits=dp.get_precision("Product Unit of Measure"), + digits="Product Unit of Measure", readonly=True, compute="_compute_qty_to_sell", store=True, @@ -69,7 +67,7 @@ class RmaOrderLine(models.Model): qty_sold = fields.Float( string="Qty Sold", copy=False, - digits=dp.get_precision("Product Unit of Measure"), + digits="Product Unit of Measure", readonly=True, compute="_compute_qty_sold", store=True, @@ -111,7 +109,6 @@ class RmaOrderLine(models.Model): self.sale_policy = self.operation_id.sale_policy or "no" return res - @api.multi def _prepare_rma_line_from_sale_order_line(self, line): self.ensure_one() if not self.type: @@ -148,8 +145,12 @@ class RmaOrderLine(models.Model): "product_qty": line.product_uom_qty, "delivery_address_id": line.order_id.partner_id.id, "invoice_address_id": line.order_id.partner_id.id, - "price_unit": line.currency_id.compute( - line.price_unit, line.currency_id, round=False + "price_unit": line.currency_id._convert( + line.price_unit, + line.currency_id, + line.company_id, + line.order_id.date_order, + round=False, ), "in_route_id": operation.in_route_id.id or route.id, "out_route_id": operation.out_route_id.id or route.id, @@ -175,14 +176,12 @@ class RmaOrderLine(models.Model): self.update(data) self._remove_other_data_origin("sale_line_id") - @api.multi def _remove_other_data_origin(self, exception): res = super(RmaOrderLine, self)._remove_other_data_origin(exception) if not exception == "sale_line_id": self.sale_line_id = False return res - @api.multi @api.constrains("sale_line_id", "partner_id") def _check_sale_partner(self): for rec in self: @@ -198,7 +197,6 @@ class RmaOrderLine(models.Model): ) ) - @api.multi def action_view_sale_order(self): action = self.env.ref("sale.action_quotations") result = action.read()[0] @@ -206,7 +204,6 @@ class RmaOrderLine(models.Model): result["domain"] = [("id", "in", order_ids)] return result - @api.multi def _get_rma_sold_qty(self): self.ensure_one() qty = 0.0 diff --git a/rma_sale/models/sale_order_line.py b/rma_sale/models/sale_order_line.py index 811521a4..2a6e1632 100644 --- a/rma_sale/models/sale_order_line.py +++ b/rma_sale/models/sale_order_line.py @@ -1,4 +1,4 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2020 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import api, fields, models @@ -33,7 +33,6 @@ class SaleOrderLine(models.Model): name_get_uid=name_get_uid, ) - @api.multi def name_get(self): res = [] if self.env.context.get("rma"): @@ -66,7 +65,6 @@ class SaleOrderLine(models.Model): comodel_name="rma.order.line", string="RMA", ondelete="restrict" ) - @api.multi def _prepare_order_line_procurement(self, group_id=False): vals = super(SaleOrderLine, self)._prepare_order_line_procurement( group_id=group_id diff --git a/rma_sale/tests/__init__.py b/rma_sale/tests/__init__.py index fae781a4..a4340678 100644 --- a/rma_sale/tests/__init__.py +++ b/rma_sale/tests/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2020 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from . import test_rma_sale diff --git a/rma_sale/tests/test_rma_sale.py b/rma_sale/tests/test_rma_sale.py index 57a469b8..7cd40421 100644 --- a/rma_sale/tests/test_rma_sale.py +++ b/rma_sale/tests/test_rma_sale.py @@ -1,4 +1,4 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2020 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo.tests import common diff --git a/rma_sale/wizards/__init__.py b/rma_sale/wizards/__init__.py index 631e0330..57786ac8 100644 --- a/rma_sale/wizards/__init__.py +++ b/rma_sale/wizards/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2020 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from . import rma_order_line_make_sale_order diff --git a/rma_sale/wizards/rma_add_sale.py b/rma_sale/wizards/rma_add_sale.py index d8198640..9d4d356f 100644 --- a/rma_sale/wizards/rma_add_sale.py +++ b/rma_sale/wizards/rma_add_sale.py @@ -1,4 +1,4 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2020 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import _, api, fields, models @@ -80,8 +80,11 @@ class RmaAddSale(models.TransientModel): "product_qty": line.product_uom_qty, "delivery_address_id": self.sale_id.partner_id.id, "invoice_address_id": self.sale_id.partner_id.id, - "price_unit": line.currency_id.compute( - line.price_unit, line.currency_id, round=False + "price_unit": line.currency_id._convert( + line.price_unit, + line.currency_id, + line.company_id, + line.order_id.date_order, ), "rma_id": self.rma_id.id, "in_route_id": operation.in_route_id.id or route.id, @@ -101,11 +104,7 @@ class RmaAddSale(models.TransientModel): @api.model def _get_rma_data(self): - data = { - "date_rma": fields.Datetime.now(), - "delivery_address_id": self.sale_id.partner_id.id, - "invoice_address_id": self.sale_id.partner_id.id, - } + data = {"date_rma": fields.Datetime.now()} return data @api.model @@ -115,7 +114,6 @@ class RmaAddSale(models.TransientModel): existing_sale_lines.append(rma_line.sale_line_id) return existing_sale_lines - @api.multi def add_lines(self): rma_line_obj = self.env["rma.order.line"] existing_sale_lines = self._get_existing_sale_lines() diff --git a/rma_sale/wizards/rma_add_sale.xml b/rma_sale/wizards/rma_add_sale.xml index 1f0bd4d8..ada0af02 100644 --- a/rma_sale/wizards/rma_add_sale.xml +++ b/rma_sale/wizards/rma_add_sale.xml @@ -54,8 +54,6 @@ Add Sale Order ir.actions.act_window rma_add_sale - rma.order - form form new diff --git a/rma_sale/wizards/rma_make_picking.py b/rma_sale/wizards/rma_make_picking.py index e05bdd13..80dc4579 100644 --- a/rma_sale/wizards/rma_make_picking.py +++ b/rma_sale/wizards/rma_make_picking.py @@ -1,4 +1,4 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2020 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import api, fields, models 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 84859c06..b8f2c420 100644 --- a/rma_sale/wizards/rma_order_line_make_sale_order.py +++ b/rma_sale/wizards/rma_order_line_make_sale_order.py @@ -1,10 +1,8 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2020 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import _, api, exceptions, fields, models -import odoo.addons.decimal_precision as dp - class RmaLineMakeSaleOrder(models.TransientModel): _name = "rma.order.line.make.sale.order" @@ -96,7 +94,6 @@ class RmaLineMakeSaleOrder(models.TransientModel): vals["price_unit"] = 0.0 return vals - @api.multi def make_sale_order(self): res = [] sale_obj = self.env["sale.order"] @@ -139,9 +136,7 @@ class RmaLineMakeSaleOrderItem(models.TransientModel): ) product_id = fields.Many2one(comodel_name="product.product", string="Product") name = fields.Char(string="Description") - product_qty = fields.Float( - string="Quantity to sell", digits=dp.get_precision("Product UoS") - ) + product_qty = fields.Float(string="Quantity to sell", digits="Product UoS") product_uom_id = fields.Many2one(comodel_name="uom.uom", string="UoM") out_warehouse_id = fields.Many2one( comodel_name="stock.warehouse", string="Outbound Warehouse" 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 065059a6..56d987ca 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 @@ -53,7 +53,6 @@ Create Sales Quotation ir.actions.act_window rma.order.line.make.sale.order - form form new diff --git a/rma_sale/wizards/rma_refund.py b/rma_sale/wizards/rma_refund.py index 26e2a855..4c9b5e33 100644 --- a/rma_sale/wizards/rma_refund.py +++ b/rma_sale/wizards/rma_refund.py @@ -1,4 +1,4 @@ -# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2020 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import api, fields, models From 9086e69f1f72336b1f46315d2ae7eb7143b7ce80 Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Mon, 9 Mar 2020 13:29:36 +0100 Subject: [PATCH 49/50] [FIX]rma_account. currency method. --- rma_account/models/rma_order.py | 8 ++++++-- rma_account/models/rma_order_line.py | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/rma_account/models/rma_order.py b/rma_account/models/rma_order.py index 02e47d4d..7680c7f2 100644 --- a/rma_account/models/rma_order.py +++ b/rma_account/models/rma_order.py @@ -49,8 +49,12 @@ class RmaOrder(models.Model): "uom_id": line.product_uom_id.id, "operation_id": operation, "product_qty": line.quantity, - "price_unit": line.move_id.currency_id.compute( - line.price_unit, line.currency_id, round=False + "price_unit": line.move_id.currency_id._convert( + line.price_unit, + line.currency_id, + line.company_id, + line.date, + round=False, ), "rma_id": self.id, } diff --git a/rma_account/models/rma_order_line.py b/rma_account/models/rma_order_line.py index 9d049572..1f871392 100644 --- a/rma_account/models/rma_order_line.py +++ b/rma_account/models/rma_order_line.py @@ -176,8 +176,12 @@ class RmaOrderLine(models.Model): "uom_id": line.product_uom_id.id, "operation_id": operation.id, "product_qty": line.quantity, - "price_unit": line.move_id.currency_id.compute( - line.price_unit, line.currency_id, round=False + "price_unit": line.move_id.currency_id._convert( + line.price_unit, + line.currency_id, + line.company_id, + line.date, + round=False, ), "delivery_address_id": line.move_id.partner_id.id, "invoice_address_id": line.move_id.partner_id.id, From c3afb525c0013b8746d309861350c0799f095eeb Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Thu, 23 Jan 2020 11:37:38 +0100 Subject: [PATCH 50/50] [ENH]rma_sale traceability --- rma/views/res_partner_view.xml | 2 +- rma_sale/models/__init__.py | 1 + rma_sale/models/sale_order.py | 36 +++++++++++++++++++ rma_sale/views/sale_order_view.xml | 23 ++++++++++++ .../wizards/rma_order_line_make_sale_order.py | 34 +++++++++++++----- .../rma_order_line_make_sale_order_view.xml | 5 +-- 6 files changed, 90 insertions(+), 11 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 64ad3fa6..3c9755f0 100644 --- 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 b8f2c420..9368251a 100644 --- a/rma_sale/wizards/rma_order_line_make_sale_order.py +++ b/rma_sale/wizards/rma_order_line_make_sale_order.py @@ -18,7 +18,9 @@ class RmaLineMakeSaleOrder(models.TransientModel): comodel_name="rma.order.line.make.sale.order.item", inverse_name="wiz_id", string="Items", + readonly=False, ) + sale_order_id = fields.Many2one( comodel_name="sale.order", string="Sales Order", @@ -67,16 +69,17 @@ 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 @api.model @@ -108,10 +111,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) @@ -130,7 +132,9 @@ 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") + line_id = fields.Many2one( + 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 ) @@ -142,3 +146,17 @@ class RmaLineMakeSaleOrderItem(models.TransientModel): 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 56d987ca..fdbba6a2 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"/>