From 1a5b49b2dd1e14c1a5f123a58808176c0c2e4be9 Mon Sep 17 00:00:00 2001 From: Jordi Ballester Date: Thu, 27 Jul 2017 18:17:19 +0200 Subject: [PATCH 01/41] 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 9dae2ef02b6263abba3c4d844a44df582326ccd2 Mon Sep 17 00:00:00 2001 From: lreficent Date: Thu, 19 Oct 2017 11:29:08 +0200 Subject: [PATCH 10/41] [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 4ed75faa4f270edcc45fde93007fa6df11982b01 Mon Sep 17 00:00:00 2001 From: lreficent Date: Thu, 19 Oct 2017 16:07:02 +0200 Subject: [PATCH 11/41] 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 03f318a72999e986ff48f3e831d1118afc0eb1a3 Mon Sep 17 00:00:00 2001 From: lreficent Date: Wed, 8 Nov 2017 16:06:18 +0100 Subject: [PATCH 12/41] [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 1408ba7803c70d00c1ee3247e7fce8a597c03939 Mon Sep 17 00:00:00 2001 From: lreficent Date: Mon, 13 Nov 2017 14:05:26 +0100 Subject: [PATCH 13/41] [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 62cd03a3e49471181f8ec895d5ec91288130952e Mon Sep 17 00:00:00 2001 From: lreficent Date: Mon, 13 Nov 2017 15:23:33 +0100 Subject: [PATCH 14/41] [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 58cffe07992a1090814ee748dbd200a308719c7e Mon Sep 17 00:00:00 2001 From: aheficent Date: Wed, 20 Dec 2017 10:21:32 +0100 Subject: [PATCH 15/41] [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 061f0f3da819d732a64bbce1ab3691d7b3800175 Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Fri, 10 Nov 2017 12:48:55 +0530 Subject: [PATCH 16/41] [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 94792145901c8a0cab7b6613d3e83989e221fe1e Mon Sep 17 00:00:00 2001 From: aheficent Date: Tue, 2 Jan 2018 13:05:09 +0100 Subject: [PATCH 17/41] [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 e977b6b9d86d66c08a0455f8666499319f1c9196 Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Fri, 5 Jan 2018 16:43:54 +0530 Subject: [PATCH 18/41] [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 4c1c78494a4c46626b2c5b9e9f11b9a16c2b06fc Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Tue, 9 Jan 2018 15:35:29 +0530 Subject: [PATCH 19/41] [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 3904bdb03b78720ff49a315e8013b7d48a195a29 Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Wed, 10 Jan 2018 13:54:55 +0100 Subject: [PATCH 20/41] [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 0557cef1a6e1893b04e8a009177108da15ac331a Mon Sep 17 00:00:00 2001 From: aheficent Date: Thu, 8 Feb 2018 15:13:38 +0100 Subject: [PATCH 21/41] [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 1b23e26a233d5f9e29b0f5b9764ea98e9cff3209 Mon Sep 17 00:00:00 2001 From: Maxime Chambreuil Date: Fri, 9 Feb 2018 12:35:23 -0600 Subject: [PATCH 22/41] [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 11925423c1acc272dd0368ad093413cbbeca5922 Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Wed, 18 Apr 2018 14:45:53 +0200 Subject: [PATCH 23/41] [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 0d0ceb213944de8bf940e9d956204cce48bef682 Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 4 May 2018 09:26:54 +0200 Subject: [PATCH 24/41] [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/41] [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 caf2b8fc3dfb02090e905f61e66bae7a743cae08 Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Wed, 16 May 2018 16:16:35 +0200 Subject: [PATCH 27/41] [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 5966aec05482841e30ed8e4b0847dd1b22eae3cf Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Thu, 24 May 2018 11:21:38 +0200 Subject: [PATCH 28/41] 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 a795059e6654908dedd4a531fd567b6c77cfad1e Mon Sep 17 00:00:00 2001 From: aaron Date: Thu, 24 May 2018 12:05:51 +0200 Subject: [PATCH 29/41] [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 ea24647878a7812b2c4ff4791047c603d11dbf96 Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Thu, 24 May 2018 12:15:50 +0200 Subject: [PATCH 30/41] [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 96a4363c3c99aee4f5d6c6b1d822c24124bf5c3a Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 25 May 2018 12:39:00 +0200 Subject: [PATCH 31/41] [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 f3aeeeeecf3de47e4268af42f3681180c15ba8c7 Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 25 May 2018 16:15:20 +0200 Subject: [PATCH 32/41] [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 df9cf9e06e5d7e54f0b8d4426945d47acf1aea5d Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 25 May 2018 16:48:50 +0200 Subject: [PATCH 33/41] [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 14fd2d5194688e053bfd0a44e635b07ff5dc7866 Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Fri, 25 May 2018 10:45:31 +0200 Subject: [PATCH 34/41] [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 b1b218ce992654ef0b350a729214daf4119cc6dc Mon Sep 17 00:00:00 2001 From: aaron Date: Thu, 31 May 2018 10:34:43 +0200 Subject: [PATCH 35/41] [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 ee52649034553f763348e30e6f3fa92659734126 Mon Sep 17 00:00:00 2001 From: aaron Date: Thu, 28 Jun 2018 11:41:14 +0200 Subject: [PATCH 36/41] [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 4ff193c87a1e8974f26c5eb9726de0344738f155 Mon Sep 17 00:00:00 2001 From: aheficent Date: Wed, 22 Aug 2018 13:36:20 +0200 Subject: [PATCH 37/41] [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 d89bb34d41b70dfe53be3e09483884af032ab2ea Mon Sep 17 00:00:00 2001 From: aheficent Date: Tue, 2 Oct 2018 12:10:58 +0200 Subject: [PATCH 38/41] [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 5ddc276a32a1dd89977899ad4f2827c60a6c6700 Mon Sep 17 00:00:00 2001 From: aheficent Date: Thu, 4 Oct 2018 16:27:11 +0200 Subject: [PATCH 39/41] [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 f22ea5d7671f60aa5793562259b144d36e98b24a Mon Sep 17 00:00:00 2001 From: aheficent Date: Mon, 3 Dec 2018 17:37:49 +0100 Subject: [PATCH 40/41] [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 51e93e105c03c8f42a25c7c67215b6af2b4f3505 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Tue, 12 Mar 2019 17:59:40 +0100 Subject: [PATCH 41/41] [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 - - +