From 0bbe59219ec108ef16b71d8f60ef3fa25b20916d Mon Sep 17 00:00:00 2001 From: aheficent Date: Tue, 2 Jan 2018 14:32:11 +0100 Subject: [PATCH 1/7] [ADD]rma_analytic --- rma_analytic/README.rst | 34 +++++++++++++++ rma_analytic/__init__.py | 5 +++ rma_analytic/__manifest__.py | 17 ++++++++ rma_analytic/models/__init__.py | 4 ++ rma_analytic/models/procurement.py | 19 ++++++++ rma_analytic/models/rma_order_line.py | 15 +++++++ rma_analytic/tests/__init__.py | 3 ++ rma_analytic/tests/test_rma_analytic.py | 30 +++++++++++++ rma_analytic/views/rma_order_line_view.xml | 50 ++++++++++++++++++++++ rma_analytic/wizards/__init__.py | 5 +++ rma_analytic/wizards/rma_add_stock_move.py | 17 ++++++++ rma_analytic/wizards/rma_make_picking.py | 18 ++++++++ 12 files changed, 217 insertions(+) create mode 100644 rma_analytic/README.rst create mode 100644 rma_analytic/__init__.py create mode 100644 rma_analytic/__manifest__.py create mode 100644 rma_analytic/models/__init__.py create mode 100644 rma_analytic/models/procurement.py create mode 100644 rma_analytic/models/rma_order_line.py create mode 100644 rma_analytic/tests/__init__.py create mode 100644 rma_analytic/tests/test_rma_analytic.py create mode 100644 rma_analytic/views/rma_order_line_view.xml create mode 100644 rma_analytic/wizards/__init__.py create mode 100644 rma_analytic/wizards/rma_add_stock_move.py create mode 100644 rma_analytic/wizards/rma_make_picking.py diff --git a/rma_analytic/README.rst b/rma_analytic/README.rst new file mode 100644 index 00000000..428285f4 --- /dev/null +++ b/rma_analytic/README.rst @@ -0,0 +1,34 @@ +.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg + :target: https://www.gnu.org/licenses/lgpl.html + :alt: License: LGPL-3 + +========================== +RMA with Analytic Accounts +========================== + +This module introduces the following features: + +* Adds the analytic account to the RMA order lines. + +* Propagates the analytic account to the procurements created + +* Introduce rules to ensure consistency + + +Usage +===== + +* Add the analytic information in the rma line or let the system fill it + from origin + + +Contributors +------------ + +* Aaron Henriquez + + +Maintainer +---------- + +This module is maintained by Eficent. \ No newline at end of file diff --git a/rma_analytic/__init__.py b/rma_analytic/__init__.py new file mode 100644 index 00000000..c5d44257 --- /dev/null +++ b/rma_analytic/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import models +from . import tests diff --git a/rma_analytic/__manifest__.py b/rma_analytic/__manifest__.py new file mode 100644 index 00000000..ef72d9c4 --- /dev/null +++ b/rma_analytic/__manifest__.py @@ -0,0 +1,17 @@ +# -*- 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": "Analytic Account in RMA", + "version": "10.0.1.0.0", + "author": "Eficent", + "license": "LGPL-3", + "website": "http://www.eficent.com", + "category": "Analytic", + "depends": ["rma", "analytic", "procurement_analytic"], + "data": [ + "views/rma_order_line_view.xml" + ], + 'installable': True, +} diff --git a/rma_analytic/models/__init__.py b/rma_analytic/models/__init__.py new file mode 100644 index 00000000..9cf2d984 --- /dev/null +++ b/rma_analytic/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import rma_order diff --git a/rma_analytic/models/procurement.py b/rma_analytic/models/procurement.py new file mode 100644 index 00000000..022cf5d6 --- /dev/null +++ b/rma_analytic/models/procurement.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# © 2018 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, exceptions, models + + +class ProcurementOrder(models.Model): + + _inherit = "procurement.order" + + +@api.constrains('analytic_account_id') +def check_analytic(self): + for order in self: + if order.analytic_account_id != order.rma_line_id.analytic_account_id: + raise exceptions.ValidationError( + _("The analytic account in the procurement it's not the same" + " as in the rma line")) diff --git a/rma_analytic/models/rma_order_line.py b/rma_analytic/models/rma_order_line.py new file mode 100644 index 00000000..3a62ce5a --- /dev/null +++ b/rma_analytic/models/rma_order_line.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# © 2018 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 + + +class RmaOrderLine(models.Model): + + _inherit = "rma.order.line" + + analytic_account_id = fields.Many2one( + comodel_name='account.analytic', + string='Analytic Account', + ) diff --git a/rma_analytic/tests/__init__.py b/rma_analytic/tests/__init__.py new file mode 100644 index 00000000..0acaa35f --- /dev/null +++ b/rma_analytic/tests/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import test_rma_analytic diff --git a/rma_analytic/tests/test_rma_analytic.py b/rma_analytic/tests/test_rma_analytic.py new file mode 100644 index 00000000..7ddac0da --- /dev/null +++ b/rma_analytic/tests/test_rma_analytic.py @@ -0,0 +1,30 @@ +# -*- 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 TestRmaAnalytic(test_rma.TestRma): + + def setUp(self): + super(TestRmaAnalytic, self).setUp() + products2move = [(self.product_1, 3), (self.product_2, 5), + (self.product_3, 2)] + self.rma_id = self._create_rma_from_move( + products2move, 'supplier', self.env.ref('base.res_partner_1'), + dropship=False) + self.analytic_1 = self.env['account.analytic.account'].create({ + 'name': 'Test account #1', + }) + + def _prepare_move(self, product, qty, src, dest): + res = super(TestRmaAnalytic, self)._prepare_move( + product, qty, src, dest) + res.update(analytic_account_id=self.analytic_1.id) + return res + + def test_analytic(self): + for line in self.rma_id.line_ids: + self.assertEqual(line.analytic_account_id, self.analytic_1, + "the analytic account is not propagated") diff --git a/rma_analytic/views/rma_order_line_view.xml b/rma_analytic/views/rma_order_line_view.xml new file mode 100644 index 00000000..92a2a788 --- /dev/null +++ b/rma_analytic/views/rma_order_line_view.xml @@ -0,0 +1,50 @@ + + + + + rma.order.line.tree + rma.order.line + + + + + + + + + + rma.order.line.supplier.tree + rma.order.line + + + + + + + + + + rma.order.line.supplier.form + rma.order.line + + + + + + + + + + rma.order.line.form + rma.order.line + + + + + + + + + + diff --git a/rma_analytic/wizards/__init__.py b/rma_analytic/wizards/__init__.py new file mode 100644 index 00000000..741a3793 --- /dev/null +++ b/rma_analytic/wizards/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2018 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from . import rma_add_stock_move diff --git a/rma_analytic/wizards/rma_add_stock_move.py b/rma_analytic/wizards/rma_add_stock_move.py new file mode 100644 index 00000000..9ef9ea05 --- /dev/null +++ b/rma_analytic/wizards/rma_add_stock_move.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# © 2018 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, models + + +class RmaAddStockMove(models.TransientModel): + _inherit = 'rma_add_stock_move' + _description = 'Wizard to add rma lines from pickings' + + @api.model + def _prepare_rma_line_from_stock_move(self, sm, lot=False): + data = super(RmaAddStockMove, self)._prepare_rma_line_from_stock_move( + sm, lot) + data.update(analytic_account_id=sm.analytic_account_id) + return data diff --git a/rma_analytic/wizards/rma_make_picking.py b/rma_analytic/wizards/rma_make_picking.py new file mode 100644 index 00000000..30561b4e --- /dev/null +++ b/rma_analytic/wizards/rma_make_picking.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# © 2018 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from odoo import models, api + + +class RmaMakePicking(models.TransientModel): + _name = 'rma_make_picking.wizard' + _description = 'Wizard to create pickings from rma lines' + + @api.model + def _get_procurement_data(self, item, group, qty, picking_type): + procurement_data = super(RmaMakePicking, self)._get_procurement_data( + item, group, qty, picking_type) + procurement_data.update( + analytic_account_id=item.line_id.analytic_account_id.id) + return procurement_data From 8e42fca74f33972036c708c56a92d74e997b4ede Mon Sep 17 00:00:00 2001 From: aheficent Date: Wed, 3 Jan 2018 14:59:06 +0100 Subject: [PATCH 2/7] [ADD]rma_account_analytic --- rma_analytic/models/__init__.py | 3 ++- rma_analytic/wizards/__init__.py | 1 + rma_analytic/wizards/rma_add_stock_move.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/rma_analytic/models/__init__.py b/rma_analytic/models/__init__.py index 9cf2d984..d6058afe 100644 --- a/rma_analytic/models/__init__.py +++ b/rma_analytic/models/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from . import rma_order +from . import rma_order_line +from . import procurement diff --git a/rma_analytic/wizards/__init__.py b/rma_analytic/wizards/__init__.py index 741a3793..c9b61ef7 100644 --- a/rma_analytic/wizards/__init__.py +++ b/rma_analytic/wizards/__init__.py @@ -3,3 +3,4 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from . import rma_add_stock_move +from . import rma_make_picking diff --git a/rma_analytic/wizards/rma_add_stock_move.py b/rma_analytic/wizards/rma_add_stock_move.py index 9ef9ea05..c2f2089c 100644 --- a/rma_analytic/wizards/rma_add_stock_move.py +++ b/rma_analytic/wizards/rma_add_stock_move.py @@ -13,5 +13,5 @@ class RmaAddStockMove(models.TransientModel): def _prepare_rma_line_from_stock_move(self, sm, lot=False): data = super(RmaAddStockMove, self)._prepare_rma_line_from_stock_move( sm, lot) - data.update(analytic_account_id=sm.analytic_account_id) + data.update(analytic_account_id=sm.analytic_account_id.id) return data From de0231abffe0ed84cbfac0cbbfcea02fbcf8d5fd Mon Sep 17 00:00:00 2001 From: aheficent Date: Wed, 3 Jan 2018 15:20:45 +0100 Subject: [PATCH 3/7] [ADD]rma_purchase_analytic [FIX]various --- rma_analytic/__init__.py | 2 +- rma_analytic/__manifest__.py | 3 ++- rma_analytic/models/rma_order_line.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/rma_analytic/__init__.py b/rma_analytic/__init__.py index c5d44257..380a9053 100644 --- a/rma_analytic/__init__.py +++ b/rma_analytic/__init__.py @@ -2,4 +2,4 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import models -from . import tests +from . import wizards diff --git a/rma_analytic/__manifest__.py b/rma_analytic/__manifest__.py index ef72d9c4..5473444b 100644 --- a/rma_analytic/__manifest__.py +++ b/rma_analytic/__manifest__.py @@ -5,7 +5,8 @@ { "name": "Analytic Account in RMA", "version": "10.0.1.0.0", - "author": "Eficent", + "author": "Eficent," + "Odoo Community Association (OCA)", "license": "LGPL-3", "website": "http://www.eficent.com", "category": "Analytic", diff --git a/rma_analytic/models/rma_order_line.py b/rma_analytic/models/rma_order_line.py index 3a62ce5a..5e8706dd 100644 --- a/rma_analytic/models/rma_order_line.py +++ b/rma_analytic/models/rma_order_line.py @@ -2,7 +2,7 @@ # © 2018 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 fields, models class RmaOrderLine(models.Model): From 050845dbaff30dcaec7044193a520f6097fc2ef0 Mon Sep 17 00:00:00 2001 From: aheficent Date: Tue, 9 Jan 2018 17:07:35 +0100 Subject: [PATCH 4/7] [UPT]oca dependencies --- rma_analytic/views/rma_order_line_view.xml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/rma_analytic/views/rma_order_line_view.xml b/rma_analytic/views/rma_order_line_view.xml index 92a2a788..b37b181f 100644 --- a/rma_analytic/views/rma_order_line_view.xml +++ b/rma_analytic/views/rma_order_line_view.xml @@ -40,11 +40,9 @@ rma.order.line - - - - - + + + From 7767859c53a4b0a8ac87d854ffcb2968601b6161 Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Wed, 10 Jan 2018 13:54:55 +0100 Subject: [PATCH 5/7] [FIX] Fixed UT & Travis --- rma_analytic/README.rst | 3 ++- rma_analytic/__manifest__.py | 3 ++- rma_analytic/models/procurement.py | 16 ++++++++-------- rma_analytic/models/rma_order_line.py | 2 +- rma_analytic/tests/__init__.py | 1 + rma_analytic/tests/test_rma_analytic.py | 24 +++++++++++++----------- 6 files changed, 27 insertions(+), 22 deletions(-) diff --git a/rma_analytic/README.rst b/rma_analytic/README.rst index 428285f4..e6c5422e 100644 --- a/rma_analytic/README.rst +++ b/rma_analytic/README.rst @@ -26,9 +26,10 @@ Contributors ------------ * Aaron Henriquez +* Serpent Consulting Services Pvt. Ltd. Maintainer ---------- -This module is maintained by Eficent. \ No newline at end of file +This module is maintained by Eficent. diff --git a/rma_analytic/__manifest__.py b/rma_analytic/__manifest__.py index 5473444b..b573cd2e 100644 --- a/rma_analytic/__manifest__.py +++ b/rma_analytic/__manifest__.py @@ -10,7 +10,8 @@ "license": "LGPL-3", "website": "http://www.eficent.com", "category": "Analytic", - "depends": ["rma", "analytic", "procurement_analytic"], + "depends": ["rma", "analytic", "procurement_analytic", + 'stock_analytic_account'], "data": [ "views/rma_order_line_view.xml" ], diff --git a/rma_analytic/models/procurement.py b/rma_analytic/models/procurement.py index 022cf5d6..f3203d42 100644 --- a/rma_analytic/models/procurement.py +++ b/rma_analytic/models/procurement.py @@ -9,11 +9,11 @@ class ProcurementOrder(models.Model): _inherit = "procurement.order" - -@api.constrains('analytic_account_id') -def check_analytic(self): - for order in self: - if order.analytic_account_id != order.rma_line_id.analytic_account_id: - raise exceptions.ValidationError( - _("The analytic account in the procurement it's not the same" - " as in the rma line")) + @api.constrains('analytic_account_id') + def check_analytic(self): + for order in self: + if (order.analytic_account_id != + order.rma_line_id.analytic_account_id): + raise exceptions.ValidationError( + _("The analytic account in the procurement it's not the " + "same as in the rma line")) diff --git a/rma_analytic/models/rma_order_line.py b/rma_analytic/models/rma_order_line.py index 5e8706dd..3b9f20d0 100644 --- a/rma_analytic/models/rma_order_line.py +++ b/rma_analytic/models/rma_order_line.py @@ -10,6 +10,6 @@ class RmaOrderLine(models.Model): _inherit = "rma.order.line" analytic_account_id = fields.Many2one( - comodel_name='account.analytic', + comodel_name='account.analytic.account', string='Analytic Account', ) diff --git a/rma_analytic/tests/__init__.py b/rma_analytic/tests/__init__.py index 0acaa35f..02fc8a66 100644 --- a/rma_analytic/tests/__init__.py +++ b/rma_analytic/tests/__init__.py @@ -1,3 +1,4 @@ # -*- 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_analytic diff --git a/rma_analytic/tests/test_rma_analytic.py b/rma_analytic/tests/test_rma_analytic.py index 7ddac0da..fdff1c61 100644 --- a/rma_analytic/tests/test_rma_analytic.py +++ b/rma_analytic/tests/test_rma_analytic.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 . import test_rma +from odoo.addons.rma.tests import test_rma class TestRmaAnalytic(test_rma.TestRma): @@ -11,20 +11,22 @@ class TestRmaAnalytic(test_rma.TestRma): super(TestRmaAnalytic, self).setUp() products2move = [(self.product_1, 3), (self.product_2, 5), (self.product_3, 2)] - self.rma_id = self._create_rma_from_move( + self.rma_ana_id = self._create_rma_from_move( products2move, 'supplier', self.env.ref('base.res_partner_1'), dropship=False) - self.analytic_1 = self.env['account.analytic.account'].create({ + + def _prepare_move(self, product, qty, src, dest, picking_in): + res = super(TestRmaAnalytic, self)._prepare_move( + product, qty, src, dest, picking_in) + analytic_1 = self.env['account.analytic.account'].create({ 'name': 'Test account #1', }) - - def _prepare_move(self, product, qty, src, dest): - res = super(TestRmaAnalytic, self)._prepare_move( - product, qty, src, dest) - res.update(analytic_account_id=self.analytic_1.id) + res.update({'analytic_account_id': analytic_1.id}) return res def test_analytic(self): - for line in self.rma_id.line_ids: - self.assertEqual(line.analytic_account_id, self.analytic_1, - "the analytic account is not propagated") + for line in self.rma_ana_id.rma_line_ids: + for move in line.move_ids: + self.assertEqual( + line.analytic_account_id, move.analytic_account_id, + "the analytic account is not propagated") From 17641cccf7e1a88aa9904546406dd0e213bcc5cb Mon Sep 17 00:00:00 2001 From: Maxime Chambreuil Date: Fri, 9 Feb 2018 12:35:23 -0600 Subject: [PATCH 6/7] [MIG] Migrate configuration and cleanup --- rma_analytic/__manifest__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rma_analytic/__manifest__.py b/rma_analytic/__manifest__.py index b573cd2e..262b5691 100644 --- a/rma_analytic/__manifest__.py +++ b/rma_analytic/__manifest__.py @@ -15,5 +15,5 @@ "data": [ "views/rma_order_line_view.xml" ], - 'installable': True, + 'installable': False, } From 1ad29d168af965463b6e5efadec06ab613a8f8a3 Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Mon, 28 Oct 2019 12:50:33 +0100 Subject: [PATCH 7/7] [MIG]rma_analytic to v12 --- rma_analytic/README.rst | 4 +- rma_analytic/__init__.py | 3 - rma_analytic/__manifest__.py | 19 +- rma_analytic/models/__init__.py | 5 +- rma_analytic/models/procurement.py | 19 -- rma_analytic/models/rma_order_line.py | 20 +- rma_analytic/models/stock_move.py | 17 ++ rma_analytic/tests/__init__.py | 3 - rma_analytic/tests/test_rma_analytic.py | 208 +++++++++++++++++++-- rma_analytic/wizards/__init__.py | 5 +- rma_analytic/wizards/rma_add_invoice.py | 18 ++ rma_analytic/wizards/rma_add_stock_move.py | 11 +- rma_analytic/wizards/rma_make_picking.py | 14 +- rma_analytic/wizards/rma_refund.py | 17 ++ 14 files changed, 284 insertions(+), 79 deletions(-) delete mode 100644 rma_analytic/models/procurement.py create mode 100644 rma_analytic/models/stock_move.py create mode 100644 rma_analytic/wizards/rma_add_invoice.py create mode 100644 rma_analytic/wizards/rma_refund.py diff --git a/rma_analytic/README.rst b/rma_analytic/README.rst index e6c5422e..4f6f749a 100644 --- a/rma_analytic/README.rst +++ b/rma_analytic/README.rst @@ -1,5 +1,5 @@ -.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg - :target: https://www.gnu.org/licenses/lgpl.html +.. image:: https://img.shields.io/badge/license-LGPL--3-blue.png + :target: https://www.gnu.org/licenses/lgpl :alt: License: LGPL-3 ========================== diff --git a/rma_analytic/__init__.py b/rma_analytic/__init__.py index 380a9053..aee8895e 100644 --- a/rma_analytic/__init__.py +++ b/rma_analytic/__init__.py @@ -1,5 +1,2 @@ -# -*- coding: utf-8 -*- -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). - from . import models from . import wizards diff --git a/rma_analytic/__manifest__.py b/rma_analytic/__manifest__.py index 262b5691..72c45266 100644 --- a/rma_analytic/__manifest__.py +++ b/rma_analytic/__manifest__.py @@ -1,19 +1,18 @@ -# -*- 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": "Analytic Account in RMA", - "version": "10.0.1.0.0", - "author": "Eficent," - "Odoo Community Association (OCA)", + "version": "12.0.1.0.0", + "author": "Eficent," "Odoo Community Association (OCA)", "license": "LGPL-3", "website": "http://www.eficent.com", "category": "Analytic", - "depends": ["rma", "analytic", "procurement_analytic", - 'stock_analytic_account'], - "data": [ - "views/rma_order_line_view.xml" + "depends": [ + "rma_account", + "stock_analytic", + "procurement_mto_analytic", ], - 'installable': False, + "data": ["views/rma_order_line_view.xml"], + "installable": True, } diff --git a/rma_analytic/models/__init__.py b/rma_analytic/models/__init__.py index d6058afe..12c8922c 100644 --- a/rma_analytic/models/__init__.py +++ b/rma_analytic/models/__init__.py @@ -1,5 +1,2 @@ -# -*- coding: utf-8 -*- -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). - +from . import stock_move from . import rma_order_line -from . import procurement diff --git a/rma_analytic/models/procurement.py b/rma_analytic/models/procurement.py deleted file mode 100644 index f3203d42..00000000 --- a/rma_analytic/models/procurement.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2018 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, exceptions, models - - -class ProcurementOrder(models.Model): - - _inherit = "procurement.order" - - @api.constrains('analytic_account_id') - def check_analytic(self): - for order in self: - if (order.analytic_account_id != - order.rma_line_id.analytic_account_id): - raise exceptions.ValidationError( - _("The analytic account in the procurement it's not the " - "same as in the rma line")) diff --git a/rma_analytic/models/rma_order_line.py b/rma_analytic/models/rma_order_line.py index 3b9f20d0..4ac13c87 100644 --- a/rma_analytic/models/rma_order_line.py +++ b/rma_analytic/models/rma_order_line.py @@ -1,8 +1,7 @@ -# -*- coding: utf-8 -*- -# © 2018 Eficent Business and IT Consulting Services S.L. +# Copyright 2018 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 +from odoo import api, fields, models class RmaOrderLine(models.Model): @@ -10,6 +9,17 @@ class RmaOrderLine(models.Model): _inherit = "rma.order.line" analytic_account_id = fields.Many2one( - comodel_name='account.analytic.account', - string='Analytic Account', + comodel_name="account.analytic.account", + string="Analytic Account", ) + + @api.multi + def _prepare_rma_line_from_inv_line(self, line): + res = super( + RmaOrderLine, self + )._prepare_rma_line_from_inv_line(line) + if line.account_analytic_id: + res.update( + analytic_account_id=line.account_analytic_id.id + ) + return res diff --git a/rma_analytic/models/stock_move.py b/rma_analytic/models/stock_move.py new file mode 100644 index 00000000..d0932dc5 --- /dev/null +++ b/rma_analytic/models/stock_move.py @@ -0,0 +1,17 @@ +# Copyright 2018 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import models + + +class StockMove(models.Model): + _inherit = "stock.move" + + def _prepare_procurement_values(self): + res = super(StockMove, self)._prepare_procurement_values() + res.update( + { + "account_analytic_id": self.rma_line_id.analytic_account_id.id + } + ) + return res diff --git a/rma_analytic/tests/__init__.py b/rma_analytic/tests/__init__.py index 02fc8a66..6e6f6965 100644 --- a/rma_analytic/tests/__init__.py +++ b/rma_analytic/tests/__init__.py @@ -1,4 +1 @@ -# -*- 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_analytic diff --git a/rma_analytic/tests/test_rma_analytic.py b/rma_analytic/tests/test_rma_analytic.py index fdff1c61..6ae294be 100644 --- a/rma_analytic/tests/test_rma_analytic.py +++ b/rma_analytic/tests/test_rma_analytic.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.addons.rma.tests import test_rma @@ -7,26 +6,199 @@ from odoo.addons.rma.tests import test_rma class TestRmaAnalytic(test_rma.TestRma): - def setUp(self): - super(TestRmaAnalytic, self).setUp() - products2move = [(self.product_1, 3), (self.product_2, 5), - (self.product_3, 2)] - self.rma_ana_id = self._create_rma_from_move( - products2move, 'supplier', self.env.ref('base.res_partner_1'), - dropship=False) + @classmethod + def setUpClass(cls): + super(TestRmaAnalytic, cls).setUpClass() + cls.rma_add_invoice_wiz = cls.env["rma_add_invoice"] + cls.rma_refund_wiz = cls.env["rma.refund"] + products2move = [ + (cls.product_1, 3), + (cls.product_2, 5), + (cls.product_3, 2), + ] + cls.rma_add_invoice_wiz = cls.env["rma_add_invoice"] + cls.rma_ana_id = cls._create_rma_from_move( + products2move, + "supplier", + cls.env.ref("base.res_partner_2"), + dropship=False, + ) + receivable_type = cls.env.ref( + "account.data_account_type_receivable" + ) + # Create Invoices: + customer_account = ( + cls.env["account.account"] + .search( + [("user_type_id", "=", receivable_type.id)], limit=1 + ) + .id + ) + cls.inv_customer = cls.env["account.invoice"].create( + { + "partner_id": cls.partner_id.id, + "account_id": customer_account, + "type": "out_invoice", + } + ) + cls.anal = cls.env["account.analytic.account"].create( + {"name": "Name"} + ) + cls.inv_line_1 = cls.env["account.invoice.line"].create( + { + "name": cls.partner_id.name, + "product_id": cls.product_1.id, + "quantity": 12.0, + "price_unit": 100.0, + "account_analytic_id": cls.anal.id, + "invoice_id": cls.inv_customer.id, + "uom_id": cls.product_1.uom_id.id, + "account_id": customer_account, + } + ) - def _prepare_move(self, product, qty, src, dest, picking_in): - res = super(TestRmaAnalytic, self)._prepare_move( - product, qty, src, dest, picking_in) - analytic_1 = self.env['account.analytic.account'].create({ - 'name': 'Test account #1', - }) - res.update({'analytic_account_id': analytic_1.id}) + @classmethod + def _prepare_move(cls, product, qty, src, dest, picking_in): + res = super(TestRmaAnalytic, cls)._prepare_move( + product, qty, src, dest, picking_in + ) + analytic_1 = cls.env["account.analytic.account"].create( + {"name": "Test account #1"} + ) + res.update({"analytic_account_id": analytic_1.id}) return res def test_analytic(self): for line in self.rma_ana_id.rma_line_ids: for move in line.move_ids: self.assertEqual( - line.analytic_account_id, move.analytic_account_id, - "the analytic account is not propagated") + line.analytic_account_id, + move.analytic_account_id, + "the analytic account is not propagated", + ) + + def test_invoice_analytic(self): + """Test wizard to create RMA from a customer invoice.""" + rma_line = ( + self.env["rma.order.line"] + .with_context(customer=True) + .new( + { + "partner_id": self.partner_id.id, + "product_id": self.product_1.id, + "operation_id": self.env.ref( + "rma.rma_operation_customer_replace" + ).id, + "in_route_id": self.env.ref( + "rma.route_rma_customer" + ), + "out_route_id": self.env.ref( + "rma.route_rma_customer" + ), + "in_warehouse_id": self.env.ref( + "stock.warehouse0" + ), + "out_warehouse_id": self.env.ref( + "stock.warehouse0" + ), + "location_id": self.env.ref( + "stock.stock_location_stock" + ), + "type": "customer", + "invoice_line_id": self.inv_line_1.id, + "uom_id": self.product_1.uom_id.id, + } + ) + ) + rma_line._onchange_invoice_line_id() + self.assertEqual( + rma_line.analytic_account_id, + self.inv_line_1.account_analytic_id, + ) + + def test_invoice_analytic02(self): + self.product_1.rma_customer_operation_id = self.env.ref( + "rma.rma_operation_customer_replace" + ).id + rma_order = ( + self.env["rma.order"] + .with_context(customer=True) + .create( + { + "name": "RMA", + "partner_id": self.partner_id.id, + "type": "customer", + "rma_line_ids": [], + } + ) + ) + add_inv = self.rma_add_invoice_wiz.with_context( + { + "customer": True, + "active_ids": [rma_order.id], + "active_model": "rma.order", + } + ).create( + { + "invoice_line_ids": [ + (6, 0, self.inv_customer.invoice_line_ids.ids) + ] + } + ) + add_inv.add_lines() + + self.assertEqual( + rma_order.mapped("rma_line_ids.analytic_account_id"), + self.inv_line_1.account_analytic_id, + ) + + def test_refund_analytic(self): + self.product_1.rma_customer_operation_id = self.env.ref( + "rma_account.rma_operation_customer_refund" + ).id + rma_line = ( + self.env["rma.order.line"] + .with_context(customer=True) + .create( + { + "partner_id": self.partner_id.id, + "product_id": self.product_1.id, + "operation_id": self.env.ref( + "rma_account.rma_operation_customer_refund" + ).id, + "in_route_id": self.env.ref( + "rma.route_rma_customer" + ).id, + "out_route_id": self.env.ref( + "rma.route_rma_customer" + ).id, + "in_warehouse_id": self.env.ref( + "stock.warehouse0" + ).id, + "out_warehouse_id": self.env.ref( + "stock.warehouse0" + ).id, + "location_id": self.env.ref( + "stock.stock_location_stock" + ).id, + "type": "customer", + "invoice_line_id": self.inv_line_1.id, + "uom_id": self.product_1.uom_id.id, + } + ) + ) + rma_line._onchange_invoice_line_id() + rma_line.action_rma_to_approve() + rma_line.action_rma_approve() + make_refund = self.rma_refund_wiz.with_context( + { + "customer": True, + "active_ids": rma_line.ids, + "active_model": "rma.order.line", + } + ).create({"description": "Test refund"}) + make_refund.invoice_refund() + self.assertEqual( + rma_line.mapped("analytic_account_id"), + rma_line.mapped("refund_line_ids.account_analytic_id"), + ) diff --git a/rma_analytic/wizards/__init__.py b/rma_analytic/wizards/__init__.py index c9b61ef7..31333467 100644 --- a/rma_analytic/wizards/__init__.py +++ b/rma_analytic/wizards/__init__.py @@ -1,6 +1,7 @@ -# -*- coding: utf-8 -*- -# © 2018 Eficent Business and IT Consulting Services S.L. +# Copyright 2018 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from . import rma_add_stock_move from . import rma_make_picking +from . import rma_add_invoice +from . import rma_refund diff --git a/rma_analytic/wizards/rma_add_invoice.py b/rma_analytic/wizards/rma_add_invoice.py new file mode 100644 index 00000000..54e86dc4 --- /dev/null +++ b/rma_analytic/wizards/rma_add_invoice.py @@ -0,0 +1,18 @@ +# © 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 models + + +class RmaAddInvoice(models.TransientModel): + _inherit = "rma_add_invoice" + + def _prepare_rma_line_from_inv_line(self, line): + res = super( + RmaAddInvoice, self + )._prepare_rma_line_from_inv_line(line) + if line.account_analytic_id: + res.update( + analytic_account_id=line.account_analytic_id.id + ) + return res diff --git a/rma_analytic/wizards/rma_add_stock_move.py b/rma_analytic/wizards/rma_add_stock_move.py index c2f2089c..fb50ab3b 100644 --- a/rma_analytic/wizards/rma_add_stock_move.py +++ b/rma_analytic/wizards/rma_add_stock_move.py @@ -1,17 +1,16 @@ -# -*- coding: utf-8 -*- -# © 2018 Eficent Business and IT Consulting Services S.L. +# Copyright 2018 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, models class RmaAddStockMove(models.TransientModel): - _inherit = 'rma_add_stock_move' - _description = 'Wizard to add rma lines from pickings' + _inherit = "rma_add_stock_move" @api.model def _prepare_rma_line_from_stock_move(self, sm, lot=False): - data = super(RmaAddStockMove, self)._prepare_rma_line_from_stock_move( - sm, lot) + data = super( + RmaAddStockMove, self + )._prepare_rma_line_from_stock_move(sm, lot) data.update(analytic_account_id=sm.analytic_account_id.id) return data diff --git a/rma_analytic/wizards/rma_make_picking.py b/rma_analytic/wizards/rma_make_picking.py index 30561b4e..a45dd9e9 100644 --- a/rma_analytic/wizards/rma_make_picking.py +++ b/rma_analytic/wizards/rma_make_picking.py @@ -1,18 +1,18 @@ -# -*- coding: utf-8 -*- -# © 2018 Eficent Business and IT Consulting Services S.L. +# Copyright 2018 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import models, api class RmaMakePicking(models.TransientModel): - _name = 'rma_make_picking.wizard' - _description = 'Wizard to create pickings from rma lines' + _inherit = "rma_make_picking.wizard" @api.model def _get_procurement_data(self, item, group, qty, picking_type): - procurement_data = super(RmaMakePicking, self)._get_procurement_data( - item, group, qty, picking_type) + procurement_data = super( + RmaMakePicking, self + )._get_procurement_data(item, group, qty, picking_type) procurement_data.update( - analytic_account_id=item.line_id.analytic_account_id.id) + analytic_account_id=item.line_id.analytic_account_id.id + ) return procurement_data diff --git a/rma_analytic/wizards/rma_refund.py b/rma_analytic/wizards/rma_refund.py new file mode 100644 index 00000000..41c3c5ea --- /dev/null +++ b/rma_analytic/wizards/rma_refund.py @@ -0,0 +1,17 @@ +# © 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, models + + +class RmaRefund(models.TransientModel): + _inherit = "rma.refund" + + @api.model + def prepare_refund_line(self, item, refund): + res = super(RmaRefund, self).prepare_refund_line(item, refund) + if item.line_id.analytic_account_id: + res.update( + account_analytic_id=item.line_id.analytic_account_id.id + ) + return res