From 5d689e79ae3bc3548b87af5b28e0ebc7d2c08100 Mon Sep 17 00:00:00 2001 From: aheficent Date: Tue, 2 Jan 2018 14:32:11 +0100 Subject: [PATCH 01/18] [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 000000000..428285f4b --- /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 000000000..c5d442576 --- /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 000000000..ef72d9c41 --- /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 000000000..9cf2d9841 --- /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 000000000..022cf5d64 --- /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 000000000..3a62ce5a9 --- /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 000000000..0acaa35fd --- /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 000000000..7ddac0dab --- /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 000000000..92a2a788d --- /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 000000000..741a37931 --- /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 000000000..9ef9ea053 --- /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 000000000..30561b4ea --- /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 5b04179e1c8bc6b6cf6658949a561c2aa897e2aa Mon Sep 17 00:00:00 2001 From: aheficent Date: Wed, 3 Jan 2018 14:59:06 +0100 Subject: [PATCH 02/18] [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 9cf2d9841..d6058afe3 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 741a37931..c9b61ef71 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 9ef9ea053..c2f2089c0 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 bc3a5fef3c05e674599816cf63a11c09b38415ce Mon Sep 17 00:00:00 2001 From: aheficent Date: Wed, 3 Jan 2018 15:20:45 +0100 Subject: [PATCH 03/18] [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 c5d442576..380a90533 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 ef72d9c41..5473444b0 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 3a62ce5a9..5e8706ddd 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 99b732a1d08194b87d25d5123c13383d023d06f6 Mon Sep 17 00:00:00 2001 From: aheficent Date: Tue, 9 Jan 2018 17:07:35 +0100 Subject: [PATCH 04/18] [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 92a2a788d..b37b181f9 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 20bffc5f2c9fab291ef473a374791f5fda067704 Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Wed, 10 Jan 2018 13:54:55 +0100 Subject: [PATCH 05/18] [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 428285f4b..e6c5422e1 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 5473444b0..b573cd2ea 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 022cf5d64..f3203d42e 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 5e8706ddd..3b9f20d04 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 0acaa35fd..02fc8a662 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 7ddac0dab..fdff1c61d 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 @@ 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( + 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({ - 'name': 'Test account #1', - }) - def _prepare_move(self, product, qty, src, dest): + def _prepare_move(self, product, qty, src, dest, picking_in): res = super(TestRmaAnalytic, self)._prepare_move( - product, qty, src, dest) - res.update(analytic_account_id=self.analytic_1.id) + 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}) 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 48df1e2a48046c889038b12b2cc9e4caf9143777 Mon Sep 17 00:00:00 2001 From: aaron Date: Wed, 16 May 2018 16:52:15 +0200 Subject: [PATCH 06/18] [FIX]rma_analytic was overwriting not inheriting --- rma_analytic/wizards/rma_make_picking.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rma_analytic/wizards/rma_make_picking.py b/rma_analytic/wizards/rma_make_picking.py index 30561b4ea..fb3624a4f 100644 --- a/rma_analytic/wizards/rma_make_picking.py +++ b/rma_analytic/wizards/rma_make_picking.py @@ -6,7 +6,7 @@ class RmaMakePicking(models.TransientModel): - _name = 'rma_make_picking.wizard' + _inherit = 'rma_make_picking.wizard' _description = 'Wizard to create pickings from rma lines' @api.model From 11e381099f5ae6ca66256afb9fb59eb2183971b0 Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 1 Jun 2018 10:59:51 +0200 Subject: [PATCH 07/18] [FIX] tests --- rma_analytic/tests/test_rma_analytic.py | 26 +++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/rma_analytic/tests/test_rma_analytic.py b/rma_analytic/tests/test_rma_analytic.py index fdff1c61d..77fea3d49 100644 --- a/rma_analytic/tests/test_rma_analytic.py +++ b/rma_analytic/tests/test_rma_analytic.py @@ -7,26 +7,28 @@ 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'), + @classmethod + def setUp(cls): + super(TestRmaAnalytic, cls).setUp() + products2move = [(cls.product_1, 3), (cls.product_2, 5), + (cls.product_3, 2)] + cls.rma_ana_id = cls._create_rma_from_move( + products2move, 'supplier', cls.env.ref('base.res_partner_1'), dropship=False) - def _prepare_move(self, product, qty, src, dest, picking_in): - res = super(TestRmaAnalytic, self)._prepare_move( + @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 = self.env['account.analytic.account'].create({ + 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: + def test_analytic(cls): + for line in cls.rma_ana_id.rma_line_ids: for move in line.move_ids: - self.assertEqual( + cls.assertEqual( line.analytic_account_id, move.analytic_account_id, "the analytic account is not propagated") From a023cab96b751fcb36d5b08817fe6f45e46cdab3 Mon Sep 17 00:00:00 2001 From: aheficent Date: Mon, 23 Jul 2018 17:11:55 +0200 Subject: [PATCH 08/18] [FIX]various fixes --- rma_analytic/__manifest__.py | 3 +- rma_analytic/models/procurement.py | 4 +- rma_analytic/tests/test_rma_analytic.py | 92 ++++++++++++++++++++---- rma_analytic/wizards/rma_make_picking.py | 2 +- 4 files changed, 83 insertions(+), 18 deletions(-) diff --git a/rma_analytic/__manifest__.py b/rma_analytic/__manifest__.py index b573cd2ea..bc4a3cf0c 100644 --- a/rma_analytic/__manifest__.py +++ b/rma_analytic/__manifest__.py @@ -10,8 +10,7 @@ "license": "LGPL-3", "website": "http://www.eficent.com", "category": "Analytic", - "depends": ["rma", "analytic", "procurement_analytic", - 'stock_analytic_account'], + "depends": ["rma", "procurement_analytic", "stock_analytic"], "data": [ "views/rma_order_line_view.xml" ], diff --git a/rma_analytic/models/procurement.py b/rma_analytic/models/procurement.py index f3203d42e..3582ed23b 100644 --- a/rma_analytic/models/procurement.py +++ b/rma_analytic/models/procurement.py @@ -9,10 +9,10 @@ class ProcurementOrder(models.Model): _inherit = "procurement.order" - @api.constrains('analytic_account_id') + @api.constrains('account_analytic_id') def check_analytic(self): for order in self: - if (order.analytic_account_id != + if (order.account_analytic_id != order.rma_line_id.analytic_account_id): raise exceptions.ValidationError( _("The analytic account in the procurement it's not the " diff --git a/rma_analytic/tests/test_rma_analytic.py b/rma_analytic/tests/test_rma_analytic.py index 77fea3d49..93e32d710 100644 --- a/rma_analytic/tests/test_rma_analytic.py +++ b/rma_analytic/tests/test_rma_analytic.py @@ -2,30 +2,96 @@ # © 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 +from odoo.tests import common -class TestRmaAnalytic(test_rma.TestRma): +class TestRmaAnalytic(common.SavepointCase): @classmethod - def setUp(cls): - super(TestRmaAnalytic, cls).setUp() + def setUpClass(cls): + super(TestRmaAnalytic, cls).setUpClass() products2move = [(cls.product_1, 3), (cls.product_2, 5), (cls.product_3, 2)] - cls.rma_ana_id = cls._create_rma_from_move( - products2move, 'supplier', cls.env.ref('base.res_partner_1'), - dropship=False) - - @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}) + cls.rma_ana_id = cls._create_rma_analytic( + products2move, 'supplier', cls.env.ref('base.res_partner_1'), + analytic=analytic_1) + + @classmethod + def _prepare_anal_move(cls, product, qty, src, dest, picking_in, analytic): + res = { + 'partner_id': cls.partner_id.id, + 'product_id': product.id, + 'name': product.partner_ref, + 'state': 'confirmed', + 'product_uom': cls.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, + 'analytic_account_id': analytic.id, + } return res + @classmethod + def _create_rma_analytic(cls, products2move, type, partner, analytic): + picking_in = cls._create_picking(partner) + moves = [] + for item in products2move: + move_values = cls._prepare_anal_move( + item[0], item[1], cls.supplier_location, + cls.stock_rma_location, picking_in, analytic) + moves.append(cls.env['stock.move'].create(move_values)) + # Create the RMA from the stock_move + rma_id = cls.rma.create( + { + 'reference': '0001', + 'type': type, + 'partner_id': partner.id, + 'company_id': cls.env.ref('base.main_company').id + }) + for move in moves: + wizard = cls.rma_add_stock_move.with_context( + {'stock_move_id': move.id, 'supplier': True, + 'active_ids': rma_id.id, + 'active_model': 'rma.order', + } + ).create({'rma_id': rma_id.id, + 'partner_id': partner.id}) + data = wizard._prepare_rma_line_from_stock_move(move) + wizard.add_lines() + + wizard = cls.rma_add_stock_move.with_context( + {'stock_move_id': move.id, 'supplier': True, + 'active_ids': [], + 'active_model': 'rma.order', + } + ).create({}) + wizard.add_lines() + wizard.add_lines() + wizard._prepare_rma_line_from_stock_move(move) + wizard.add_lines() + + cls.line = cls.rma_line.create(data) + # approve the RMA Line + cls.line.action_rma_to_approve() + cls.line.action_rma_approve() + rma_id._get_default_type() + 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() + return rma_id + def test_analytic(cls): for line in cls.rma_ana_id.rma_line_ids: for move in line.move_ids: diff --git a/rma_analytic/wizards/rma_make_picking.py b/rma_analytic/wizards/rma_make_picking.py index fb3624a4f..daf68fddf 100644 --- a/rma_analytic/wizards/rma_make_picking.py +++ b/rma_analytic/wizards/rma_make_picking.py @@ -14,5 +14,5 @@ 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) + account_analytic_id=item.line_id.analytic_account_id.id) return procurement_data From de225e234ff67abd89602900ad69be868714415c Mon Sep 17 00:00:00 2001 From: aheficent Date: Fri, 3 Aug 2018 12:36:15 +0200 Subject: [PATCH 09/18] [FIX]tests --- rma_analytic/tests/test_rma_analytic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rma_analytic/tests/test_rma_analytic.py b/rma_analytic/tests/test_rma_analytic.py index 93e32d710..e74b70431 100644 --- a/rma_analytic/tests/test_rma_analytic.py +++ b/rma_analytic/tests/test_rma_analytic.py @@ -2,10 +2,10 @@ # © 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -from odoo.tests import common +from odoo.addons.rma.tests import test_rma -class TestRmaAnalytic(common.SavepointCase): +class TestRmaAnalytic(test_rma.TestRma): @classmethod def setUpClass(cls): From 7fd6f54a93728fe9d97028b0d2f556875c2c271f Mon Sep 17 00:00:00 2001 From: aheficent Date: Wed, 31 Oct 2018 18:06:57 +0100 Subject: [PATCH 10/18] [FIX]rma_analytic tests --- rma_analytic/tests/test_rma_analytic.py | 78 ++++++++++++------------- 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/rma_analytic/tests/test_rma_analytic.py b/rma_analytic/tests/test_rma_analytic.py index e74b70431..81f8a28ec 100644 --- a/rma_analytic/tests/test_rma_analytic.py +++ b/rma_analytic/tests/test_rma_analytic.py @@ -2,22 +2,39 @@ # © 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 +from odoo.tests import common -class TestRmaAnalytic(test_rma.TestRma): +class TestRmaAnalytic(common.SavepointCase): @classmethod def setUpClass(cls): super(TestRmaAnalytic, cls).setUpClass() - products2move = [(cls.product_1, 3), (cls.product_2, 5), - (cls.product_3, 2)] - analytic_1 = cls.env['account.analytic.account'].create({ + cls.stock_picking_model = cls.env['stock.picking'] + cls.rma_line_model = cls.env['rma.order.line'] + cls.rma_model = cls.env['rma.order'] + cls.rma_add_stock_move = cls.env['rma_add_stock_move'] + cls.stock_location = cls.env.ref('stock.stock_location_stock') + cls.product_1 = cls.env.ref('product.product_product_25') + cls.customer_location = cls.env.ref( + 'stock.stock_location_customers') + cls.product_uom_id = cls.env.ref('product.product_uom_unit') + products2move = [(cls.product_1, 3), ] + cls.analytic_1 = cls.env['account.analytic.account'].create({ 'name': 'Test account #1', }) + cls.partner_id = cls.env.ref('base.res_partner_1') cls.rma_ana_id = cls._create_rma_analytic( - products2move, 'supplier', cls.env.ref('base.res_partner_1'), - analytic=analytic_1) + products2move, cls.partner_id) + + @classmethod + def _create_picking(cls, partner): + return cls.stock_picking_model.create({ + 'partner_id': partner.id, + 'picking_type_id': cls.env.ref('stock.picking_type_in').id, + 'location_id': cls.stock_location.id, + 'location_dest_id': cls.customer_location.id + }) @classmethod def _prepare_anal_move(cls, product, qty, src, dest, picking_in, analytic): @@ -37,59 +54,38 @@ def _prepare_anal_move(cls, product, qty, src, dest, picking_in, analytic): return res @classmethod - def _create_rma_analytic(cls, products2move, type, partner, analytic): + def _create_rma_analytic(cls, products2move, partner): picking_in = cls._create_picking(partner) moves = [] for item in products2move: move_values = cls._prepare_anal_move( - item[0], item[1], cls.supplier_location, - cls.stock_rma_location, picking_in, analytic) + item[0], item[1], cls.stock_location, + cls.customer_location, picking_in, cls.analytic_1) moves.append(cls.env['stock.move'].create(move_values)) - # Create the RMA from the stock_move - rma_id = cls.rma.create( + + rma_id = cls.rma_model.create( { 'reference': '0001', - 'type': type, + 'type': 'customer', 'partner_id': partner.id, 'company_id': cls.env.ref('base.main_company').id }) for move in moves: wizard = cls.rma_add_stock_move.with_context( - {'stock_move_id': move.id, 'supplier': True, + {'stock_move_id': move.id, 'customer': True, 'active_ids': rma_id.id, 'active_model': 'rma.order', } - ).create({'rma_id': rma_id.id, - 'partner_id': partner.id}) + ).create({}) data = wizard._prepare_rma_line_from_stock_move(move) wizard.add_lines() - wizard = cls.rma_add_stock_move.with_context( - {'stock_move_id': move.id, 'supplier': True, - 'active_ids': [], - 'active_model': 'rma.order', - } - ).create({}) - wizard.add_lines() - wizard.add_lines() + for operation in move.product_id.rma_customer_operation_id: + operation.in_route_id = False + move.product_id.categ_id.rma_customer_operation_id = False + move.product_id.rma_customer_operation_id = False wizard._prepare_rma_line_from_stock_move(move) - wizard.add_lines() - - cls.line = cls.rma_line.create(data) - # approve the RMA Line - cls.line.action_rma_to_approve() - cls.line.action_rma_approve() - rma_id._get_default_type() - 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() + cls.line = cls.rma_line_model.create(data) return rma_id def test_analytic(cls): From 86c57cfb39d05d27ecf006119e10d914ad88c59b Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Mon, 28 Oct 2019 18:11:57 +0100 Subject: [PATCH 11/18] [FIX]rma_analytic. Propagate analytic to other models --- rma_analytic/__manifest__.py | 1 + rma_analytic/models/rma_order_line.py | 13 +- rma_analytic/tests/test_rma_analytic.py | 267 +++++++++++++++++++----- rma_analytic/wizards/__init__.py | 2 + rma_analytic/wizards/rma_add_invoice.py | 19 ++ rma_analytic/wizards/rma_refund.py | 18 ++ 6 files changed, 262 insertions(+), 58 deletions(-) create mode 100644 rma_analytic/wizards/rma_add_invoice.py create mode 100644 rma_analytic/wizards/rma_refund.py diff --git a/rma_analytic/__manifest__.py b/rma_analytic/__manifest__.py index bc4a3cf0c..032c09ee9 100644 --- a/rma_analytic/__manifest__.py +++ b/rma_analytic/__manifest__.py @@ -15,4 +15,5 @@ "views/rma_order_line_view.xml" ], 'installable': True, + } diff --git a/rma_analytic/models/rma_order_line.py b/rma_analytic/models/rma_order_line.py index 3b9f20d04..8d125ce40 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 fields, models +from odoo import api, fields, models class RmaOrderLine(models.Model): @@ -13,3 +13,14 @@ class RmaOrderLine(models.Model): 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/tests/test_rma_analytic.py b/rma_analytic/tests/test_rma_analytic.py index 81f8a28ec..e8298a15e 100644 --- a/rma_analytic/tests/test_rma_analytic.py +++ b/rma_analytic/tests/test_rma_analytic.py @@ -2,55 +2,70 @@ # © 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -from odoo.tests import common +from odoo.addons.rma.tests import test_rma -class TestRmaAnalytic(common.SavepointCase): - +class TestRmaAnalytic(test_rma.TestRma): @classmethod def setUpClass(cls): super(TestRmaAnalytic, cls).setUpClass() - cls.stock_picking_model = cls.env['stock.picking'] - cls.rma_line_model = cls.env['rma.order.line'] - cls.rma_model = cls.env['rma.order'] - cls.rma_add_stock_move = cls.env['rma_add_stock_move'] - cls.stock_location = cls.env.ref('stock.stock_location_stock') - cls.product_1 = cls.env.ref('product.product_product_25') - cls.customer_location = cls.env.ref( - 'stock.stock_location_customers') - cls.product_uom_id = cls.env.ref('product.product_uom_unit') - products2move = [(cls.product_1, 3), ] - cls.analytic_1 = cls.env['account.analytic.account'].create({ - 'name': 'Test account #1', - }) - cls.partner_id = cls.env.ref('base.res_partner_1') - cls.rma_ana_id = cls._create_rma_analytic( - products2move, cls.partner_id) - - @classmethod - def _create_picking(cls, partner): - return cls.stock_picking_model.create({ - 'partner_id': partner.id, - 'picking_type_id': cls.env.ref('stock.picking_type_in').id, - 'location_id': cls.stock_location.id, - 'location_dest_id': cls.customer_location.id - }) + 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, + } + ) @classmethod - def _prepare_anal_move(cls, product, qty, src, dest, picking_in, analytic): - res = { - 'partner_id': cls.partner_id.id, - 'product_id': product.id, - 'name': product.partner_ref, - 'state': 'confirmed', - 'product_uom': cls.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, - 'analytic_account_id': analytic.id, - } + 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 @classmethod @@ -59,28 +74,38 @@ def _create_rma_analytic(cls, products2move, partner): moves = [] for item in products2move: move_values = cls._prepare_anal_move( - item[0], item[1], cls.stock_location, - cls.customer_location, picking_in, cls.analytic_1) - moves.append(cls.env['stock.move'].create(move_values)) + item[0], + item[1], + cls.stock_location, + cls.customer_location, + picking_in, + cls.analytic_1, + ) + moves.append(cls.env["stock.move"].create(move_values)) rma_id = cls.rma_model.create( { - 'reference': '0001', - 'type': 'customer', - 'partner_id': partner.id, - 'company_id': cls.env.ref('base.main_company').id - }) + "reference": "0001", + "type": "customer", + "partner_id": partner.id, + "company_id": cls.env.ref("base.main_company").id, + } + ) for move in moves: wizard = cls.rma_add_stock_move.with_context( - {'stock_move_id': move.id, 'customer': True, - 'active_ids': rma_id.id, - 'active_model': 'rma.order', - } + { + "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() - for operation in move.product_id.rma_customer_operation_id: + for ( + operation + ) in move.product_id.rma_customer_operation_id: operation.in_route_id = False move.product_id.categ_id.rma_customer_operation_id = False move.product_id.rma_customer_operation_id = False @@ -92,5 +117,133 @@ def test_analytic(cls): for line in cls.rma_ana_id.rma_line_ids: for move in line.move_ids: cls.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(cls): + """Test wizard to create RMA from a customer invoice.""" + rma_line = ( + cls.env["rma.order.line"] + .with_context(customer=True) + .new( + { + "partner_id": cls.partner_id.id, + "product_id": cls.product_1.id, + "operation_id": cls.env.ref( + "rma.rma_operation_customer_replace" + ).id, + "in_route_id": cls.env.ref( + "rma.route_rma_customer" + ), + "out_route_id": cls.env.ref( + "rma.route_rma_customer" + ), + "in_warehouse_id": cls.env.ref( + "stock.warehouse0" + ), + "out_warehouse_id": cls.env.ref( + "stock.warehouse0" + ), + "location_id": cls.env.ref( + "stock.stock_location_stock" + ), + "type": "customer", + "invoice_line_id": cls.inv_line_1.id, + "uom_id": cls.product_1.uom_id.id, + } + ) + ) + rma_line._onchange_invoice_line_id() + cls.assertEqual( + rma_line.analytic_account_id, + cls.inv_line_1.account_analytic_id, + ) + + def test_invoice_analytic02(cls): + cls.product_1.rma_customer_operation_id = cls.env.ref( + "rma.rma_operation_customer_replace" + ).id + rma_order = ( + cls.env["rma.order"] + .with_context(customer=True) + .create( + { + "name": "RMA", + "partner_id": cls.partner_id.id, + "type": "customer", + "rma_line_ids": [], + } + ) + ) + add_inv = cls.rma_add_invoice_wiz.with_context( + { + "customer": True, + "active_ids": [rma_order.id], + "active_model": "rma.order", + } + ).create( + { + "invoice_line_ids": [ + (6, 0, cls.inv_customer.invoice_line_ids.ids) + ] + } + ) + add_inv.add_lines() + + cls.assertEqual( + rma_order.mapped("rma_line_ids.analytic_account_id"), + cls.inv_line_1.account_analytic_id, + ) + + def test_refund_analytic(cls): + cls.product_1.rma_customer_operation_id = cls.env.ref( + "rma_account.rma_operation_customer_refund" + ).id + rma_line = ( + cls.env["rma.order.line"] + .with_context(customer=True) + .create( + { + "partner_id": cls.partner_id.id, + "product_id": cls.product_1.id, + "operation_id": cls.env.ref( + "rma_account.rma_operation_customer_refund" + ).id, + "in_route_id": cls.env.ref( + "rma.route_rma_customer" + ).id, + "out_route_id": cls.env.ref( + "rma.route_rma_customer" + ).id, + "in_warehouse_id": cls.env.ref( + "stock.warehouse0" + ).id, + "out_warehouse_id": cls.env.ref( + "stock.warehouse0" + ).id, + "location_id": cls.env.ref( + "stock.stock_location_stock" + ).id, + "type": "customer", + "invoice_line_id": cls.inv_line_1.id, + "uom_id": cls.product_1.uom_id.id, + } + ) + ) + rma_line._onchange_invoice_line_id() + rma_line.action_rma_to_approve() + rma_line.action_rma_approve() + make_refund = cls.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() + cls.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 c9b61ef71..99d252913 100644 --- a/rma_analytic/wizards/__init__.py +++ b/rma_analytic/wizards/__init__.py @@ -4,3 +4,5 @@ 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 000000000..02c81c1f6 --- /dev/null +++ b/rma_analytic/wizards/rma_add_invoice.py @@ -0,0 +1,19 @@ +# -*- 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 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_refund.py b/rma_analytic/wizards/rma_refund.py new file mode 100644 index 000000000..583c562e0 --- /dev/null +++ b/rma_analytic/wizards/rma_refund.py @@ -0,0 +1,18 @@ +# -*- 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 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 From 98d6ff39ba2c315bf2b891216d0e305956e96e6f Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Tue, 29 Oct 2019 10:43:37 +0100 Subject: [PATCH 12/18] [FIX]minor crap in several modules --- rma_analytic/tests/test_rma_analytic.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rma_analytic/tests/test_rma_analytic.py b/rma_analytic/tests/test_rma_analytic.py index e8298a15e..52f31fdd6 100644 --- a/rma_analytic/tests/test_rma_analytic.py +++ b/rma_analytic/tests/test_rma_analytic.py @@ -228,6 +228,8 @@ def test_refund_analytic(cls): ).id, "type": "customer", "invoice_line_id": cls.inv_line_1.id, + "delivery_policy": "no", + "receipt_policy": "ordered", "uom_id": cls.product_1.uom_id.id, } ) From bf10bd66122a36ca5f7888cfa25578ca9f07f33f Mon Sep 17 00:00:00 2001 From: mreficent Date: Wed, 30 Oct 2019 20:23:51 +0100 Subject: [PATCH 13/18] [FIX] tests and import openerp --- rma_analytic/tests/test_rma_analytic.py | 87 ++++++++++++------------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/rma_analytic/tests/test_rma_analytic.py b/rma_analytic/tests/test_rma_analytic.py index 52f31fdd6..80f5e8c32 100644 --- a/rma_analytic/tests/test_rma_analytic.py +++ b/rma_analytic/tests/test_rma_analytic.py @@ -6,6 +6,7 @@ class TestRmaAnalytic(test_rma.TestRma): + @classmethod def setUpClass(cls): super(TestRmaAnalytic, cls).setUpClass() @@ -103,81 +104,79 @@ def _create_rma_analytic(cls, products2move, partner): data = wizard._prepare_rma_line_from_stock_move(move) wizard.add_lines() - for ( - operation - ) in move.product_id.rma_customer_operation_id: - operation.in_route_id = False + if move.product_id.rma_customer_operation_id: + move.product_id.rma_customer_operation_id.in_route_id = False move.product_id.categ_id.rma_customer_operation_id = False move.product_id.rma_customer_operation_id = False wizard._prepare_rma_line_from_stock_move(move) cls.line = cls.rma_line_model.create(data) return rma_id - def test_analytic(cls): - for line in cls.rma_ana_id.rma_line_ids: + def test_analytic(self): + for line in self.rma_ana_id.rma_line_ids: for move in line.move_ids: - cls.assertEqual( + self.assertEqual( line.analytic_account_id, move.analytic_account_id, "the analytic account is not propagated", ) - def test_invoice_analytic(cls): + def test_invoice_analytic(self): """Test wizard to create RMA from a customer invoice.""" rma_line = ( - cls.env["rma.order.line"] + self.env["rma.order.line"] .with_context(customer=True) .new( { - "partner_id": cls.partner_id.id, - "product_id": cls.product_1.id, - "operation_id": cls.env.ref( + "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": cls.env.ref( + "in_route_id": self.env.ref( "rma.route_rma_customer" ), - "out_route_id": cls.env.ref( + "out_route_id": self.env.ref( "rma.route_rma_customer" ), - "in_warehouse_id": cls.env.ref( + "in_warehouse_id": self.env.ref( "stock.warehouse0" ), - "out_warehouse_id": cls.env.ref( + "out_warehouse_id": self.env.ref( "stock.warehouse0" ), - "location_id": cls.env.ref( + "location_id": self.env.ref( "stock.stock_location_stock" ), "type": "customer", - "invoice_line_id": cls.inv_line_1.id, - "uom_id": cls.product_1.uom_id.id, + "invoice_line_id": self.inv_line_1.id, + "uom_id": self.product_1.uom_id.id, } ) ) rma_line._onchange_invoice_line_id() - cls.assertEqual( + self.assertEqual( rma_line.analytic_account_id, - cls.inv_line_1.account_analytic_id, + self.inv_line_1.account_analytic_id, ) - def test_invoice_analytic02(cls): - cls.product_1.rma_customer_operation_id = cls.env.ref( + def test_invoice_analytic02(self): + self.product_1.rma_customer_operation_id = self.env.ref( "rma.rma_operation_customer_replace" ).id rma_order = ( - cls.env["rma.order"] + self.env["rma.order"] .with_context(customer=True) .create( { "name": "RMA", - "partner_id": cls.partner_id.id, + "partner_id": self.partner_id.id, "type": "customer", "rma_line_ids": [], } ) ) - add_inv = cls.rma_add_invoice_wiz.with_context( + add_inv = self.rma_add_invoice_wiz.with_context( { "customer": True, "active_ids": [rma_order.id], @@ -186,58 +185,58 @@ def test_invoice_analytic02(cls): ).create( { "invoice_line_ids": [ - (6, 0, cls.inv_customer.invoice_line_ids.ids) + (6, 0, self.inv_customer.invoice_line_ids.ids) ] } ) add_inv.add_lines() - cls.assertEqual( + self.assertEqual( rma_order.mapped("rma_line_ids.analytic_account_id"), - cls.inv_line_1.account_analytic_id, + self.inv_line_1.account_analytic_id, ) - def test_refund_analytic(cls): - cls.product_1.rma_customer_operation_id = cls.env.ref( + def test_refund_analytic(self): + self.product_1.rma_customer_operation_id = self.env.ref( "rma_account.rma_operation_customer_refund" ).id rma_line = ( - cls.env["rma.order.line"] + self.env["rma.order.line"] .with_context(customer=True) .create( { - "partner_id": cls.partner_id.id, - "product_id": cls.product_1.id, - "operation_id": cls.env.ref( + "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": cls.env.ref( + "in_route_id": self.env.ref( "rma.route_rma_customer" ).id, - "out_route_id": cls.env.ref( + "out_route_id": self.env.ref( "rma.route_rma_customer" ).id, - "in_warehouse_id": cls.env.ref( + "in_warehouse_id": self.env.ref( "stock.warehouse0" ).id, - "out_warehouse_id": cls.env.ref( + "out_warehouse_id": self.env.ref( "stock.warehouse0" ).id, - "location_id": cls.env.ref( + "location_id": self.env.ref( "stock.stock_location_stock" ).id, "type": "customer", - "invoice_line_id": cls.inv_line_1.id, + "invoice_line_id": self.inv_line_1.id, "delivery_policy": "no", "receipt_policy": "ordered", - "uom_id": cls.product_1.uom_id.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 = cls.rma_refund_wiz.with_context( + make_refund = self.rma_refund_wiz.with_context( { "customer": True, "active_ids": rma_line.ids, @@ -245,7 +244,7 @@ def test_refund_analytic(cls): } ).create({"description": "Test refund"}) make_refund.invoice_refund() - cls.assertEqual( + self.assertEqual( rma_line.mapped("analytic_account_id"), rma_line.mapped("refund_line_ids.account_analytic_id"), ) From 8721076190df87be9d2baa8a15cb955cfb895c95 Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Fri, 22 May 2020 12:00:27 +0200 Subject: [PATCH 14/18] [FIX]rma_analytic/models/procurement.py constraint in procurement. --- rma_analytic/models/procurement.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rma_analytic/models/procurement.py b/rma_analytic/models/procurement.py index 3582ed23b..90968ac6b 100644 --- a/rma_analytic/models/procurement.py +++ b/rma_analytic/models/procurement.py @@ -12,8 +12,8 @@ class ProcurementOrder(models.Model): @api.constrains('account_analytic_id') def check_analytic(self): for order in self: - if (order.account_analytic_id != - order.rma_line_id.analytic_account_id): + if order.rma_line_id and (order.account_analytic_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")) From cdf617e15950addc04fae905ecf370a2bf72f421 Mon Sep 17 00:00:00 2001 From: JasminSForgeFlow Date: Tue, 18 Jul 2023 16:28:37 +0530 Subject: [PATCH 15/18] [IMP] rma_analytic: black, isort, prettier --- rma_analytic/__init__.py | 1 - rma_analytic/__manifest__.py | 13 ++--- rma_analytic/models/__init__.py | 1 - rma_analytic/models/procurement.py | 15 +++--- rma_analytic/models/rma_order_line.py | 13 ++--- rma_analytic/tests/__init__.py | 1 - rma_analytic/tests/test_rma_analytic.py | 62 +++++----------------- rma_analytic/views/rma_order_line_view.xml | 30 +++++++---- rma_analytic/wizards/__init__.py | 1 - rma_analytic/wizards/rma_add_invoice.py | 9 +--- rma_analytic/wizards/rma_add_stock_move.py | 8 ++- rma_analytic/wizards/rma_make_picking.py | 13 +++-- rma_analytic/wizards/rma_refund.py | 5 +- 13 files changed, 64 insertions(+), 108 deletions(-) diff --git a/rma_analytic/__init__.py b/rma_analytic/__init__.py index 380a90533..69f54da63 100644 --- a/rma_analytic/__init__.py +++ b/rma_analytic/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import models diff --git a/rma_analytic/__manifest__.py b/rma_analytic/__manifest__.py index 032c09ee9..ec1b1fa43 100644 --- a/rma_analytic/__manifest__.py +++ b/rma_analytic/__manifest__.py @@ -1,19 +1,14 @@ -# -*- 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," - "Odoo Community Association (OCA)", + "author": "Eficent," "Odoo Community Association (OCA)", "license": "LGPL-3", - "website": "http://www.eficent.com", + "website": "https://github.com/ForgeFlow/stock-rma", "category": "Analytic", "depends": ["rma", "procurement_analytic", "stock_analytic"], - "data": [ - "views/rma_order_line_view.xml" - ], - 'installable': True, - + "data": ["views/rma_order_line_view.xml"], + "installable": True, } diff --git a/rma_analytic/models/__init__.py b/rma_analytic/models/__init__.py index d6058afe3..fa41cc2bc 100644 --- a/rma_analytic/models/__init__.py +++ b/rma_analytic/models/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import rma_order_line diff --git a/rma_analytic/models/procurement.py b/rma_analytic/models/procurement.py index 90968ac6b..ee3188c2b 100644 --- a/rma_analytic/models/procurement.py +++ b/rma_analytic/models/procurement.py @@ -1,4 +1,3 @@ -# -*- 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). @@ -9,11 +8,15 @@ class ProcurementOrder(models.Model): _inherit = "procurement.order" - @api.constrains('account_analytic_id') + @api.constrains("account_analytic_id") def check_analytic(self): for order in self: - if order.rma_line_id and (order.account_analytic_id != - order.rma_line_id.analytic_account_id): + if order.rma_line_id and ( + order.account_analytic_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")) + _( + "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 8d125ce40..dd29ce2fa 100644 --- a/rma_analytic/models/rma_order_line.py +++ b/rma_analytic/models/rma_order_line.py @@ -1,4 +1,3 @@ -# -*- 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). @@ -10,17 +9,13 @@ 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) + 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 - ) + res.update(analytic_account_id=line.account_analytic_id.id) return res diff --git a/rma_analytic/tests/__init__.py b/rma_analytic/tests/__init__.py index 02fc8a662..e3e7b7fa6 100644 --- a/rma_analytic/tests/__init__.py +++ b/rma_analytic/tests/__init__.py @@ -1,4 +1,3 @@ -# -*- 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 80f5e8c32..f18ea2ef9 100644 --- a/rma_analytic/tests/test_rma_analytic.py +++ b/rma_analytic/tests/test_rma_analytic.py @@ -1,4 +1,3 @@ -# -*- 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) @@ -6,7 +5,6 @@ class TestRmaAnalytic(test_rma.TestRma): - @classmethod def setUpClass(cls): super(TestRmaAnalytic, cls).setUpClass() @@ -24,15 +22,11 @@ def setUpClass(cls): cls.env.ref("base.res_partner_2"), dropship=False, ) - receivable_type = cls.env.ref( - "account.data_account_type_receivable" - ) + 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 - ) + .search([("user_type_id", "=", receivable_type.id)], limit=1) .id ) cls.inv_customer = cls.env["account.invoice"].create( @@ -42,9 +36,7 @@ def setUpClass(cls): "type": "out_invoice", } ) - cls.anal = cls.env["account.analytic.account"].create( - {"name": "Name"} - ) + 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, @@ -133,21 +125,11 @@ def test_invoice_analytic(self): "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" - ), + "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, @@ -182,13 +164,7 @@ def test_invoice_analytic02(self): "active_ids": [rma_order.id], "active_model": "rma.order", } - ).create( - { - "invoice_line_ids": [ - (6, 0, self.inv_customer.invoice_line_ids.ids) - ] - } - ) + ).create({"invoice_line_ids": [(6, 0, self.inv_customer.invoice_line_ids.ids)]}) add_inv.add_lines() self.assertEqual( @@ -210,21 +186,11 @@ def test_refund_analytic(self): "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, + "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, "delivery_policy": "no", diff --git a/rma_analytic/views/rma_order_line_view.xml b/rma_analytic/views/rma_order_line_view.xml index b37b181f9..61c098c9a 100644 --- a/rma_analytic/views/rma_order_line_view.xml +++ b/rma_analytic/views/rma_order_line_view.xml @@ -1,14 +1,17 @@ - + rma.order.line.tree rma.order.line - + - + @@ -16,10 +19,13 @@ rma.order.line.supplier.tree rma.order.line - + - + @@ -27,10 +33,13 @@ rma.order.line.supplier.form rma.order.line - + - + @@ -38,10 +47,13 @@ rma.order.line.form rma.order.line - + - + diff --git a/rma_analytic/wizards/__init__.py b/rma_analytic/wizards/__init__.py index 99d252913..65f9813ba 100644 --- a/rma_analytic/wizards/__init__.py +++ b/rma_analytic/wizards/__init__.py @@ -1,4 +1,3 @@ -# -*- 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) diff --git a/rma_analytic/wizards/rma_add_invoice.py b/rma_analytic/wizards/rma_add_invoice.py index 02c81c1f6..bef3d6103 100644 --- a/rma_analytic/wizards/rma_add_invoice.py +++ b/rma_analytic/wizards/rma_add_invoice.py @@ -1,4 +1,3 @@ -# -*- 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) @@ -9,11 +8,7 @@ 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) + 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 - ) + 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 c2f2089c0..8318713ee 100644 --- a/rma_analytic/wizards/rma_add_stock_move.py +++ b/rma_analytic/wizards/rma_add_stock_move.py @@ -1,4 +1,3 @@ -# -*- 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) @@ -6,12 +5,11 @@ class RmaAddStockMove(models.TransientModel): - _inherit = 'rma_add_stock_move' - _description = 'Wizard to add rma lines from pickings' + _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 = 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 daf68fddf..46591ceec 100644 --- a/rma_analytic/wizards/rma_make_picking.py +++ b/rma_analytic/wizards/rma_make_picking.py @@ -1,18 +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 models, api +from odoo import api, models class RmaMakePicking(models.TransientModel): - _inherit = 'rma_make_picking.wizard' - _description = 'Wizard to create pickings from rma lines' + _inherit = "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( - account_analytic_id=item.line_id.analytic_account_id.id) + item, group, qty, picking_type + ) + procurement_data.update(account_analytic_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 index 583c562e0..d6e185182 100644 --- a/rma_analytic/wizards/rma_refund.py +++ b/rma_analytic/wizards/rma_refund.py @@ -1,4 +1,3 @@ -# -*- 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) @@ -12,7 +11,5 @@ class RmaRefund(models.TransientModel): 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 - ) + res.update(account_analytic_id=item.line_id.analytic_account_id.id) return res From ce82c5580491efbe005973add2b836edf979fd0f Mon Sep 17 00:00:00 2001 From: JasminSForgeFlow Date: Tue, 18 Jul 2023 18:03:27 +0530 Subject: [PATCH 16/18] [MIG] rma_analytic: Migration to 15.0 --- rma_analytic/README.rst | 9 +- rma_analytic/__init__.py | 2 - rma_analytic/__manifest__.py | 14 +- rma_analytic/models/__init__.py | 4 +- rma_analytic/models/procurement.py | 22 -- rma_analytic/models/rma_order_line.py | 9 +- rma_analytic/models/stock_rule.py | 33 +++ rma_analytic/tests/__init__.py | 2 - rma_analytic/tests/test_rma_analytic.py | 211 +++++++------------ rma_analytic/views/rma_order_line_view.xml | 2 +- rma_analytic/wizards/__init__.py | 4 +- rma_analytic/wizards/rma_add_account_move.py | 14 ++ rma_analytic/wizards/rma_add_invoice.py | 6 +- rma_analytic/wizards/rma_add_stock_move.py | 6 +- rma_analytic/wizards/rma_make_picking.py | 5 +- rma_analytic/wizards/rma_refund.py | 8 +- 16 files changed, 160 insertions(+), 191 deletions(-) delete mode 100644 rma_analytic/models/procurement.py create mode 100644 rma_analytic/models/stock_rule.py create mode 100644 rma_analytic/wizards/rma_add_account_move.py diff --git a/rma_analytic/README.rst b/rma_analytic/README.rst index e6c5422e1..4cbac0ece 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 ========================== @@ -25,11 +25,12 @@ Usage Contributors ------------ -* Aaron Henriquez +* Aaron Henriquez +* Juany Davila * Serpent Consulting Services Pvt. Ltd. Maintainer ---------- -This module is maintained by Eficent. +This module is maintained by ForgeFlow. diff --git a/rma_analytic/__init__.py b/rma_analytic/__init__.py index 69f54da63..aee8895e7 100644 --- a/rma_analytic/__init__.py +++ b/rma_analytic/__init__.py @@ -1,4 +1,2 @@ -# 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 ec1b1fa43..e93bb50ce 100644 --- a/rma_analytic/__manifest__.py +++ b/rma_analytic/__manifest__.py @@ -1,14 +1,18 @@ -# © 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2023 ForgeFlow 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)", - "license": "LGPL-3", + "version": "15.0.1.0.0", + "author": "ForgeFlow," "Odoo Community Association (OCA)", + "license": "AGPL-3", "website": "https://github.com/ForgeFlow/stock-rma", "category": "Analytic", - "depends": ["rma", "procurement_analytic", "stock_analytic"], + "depends": [ + "rma_account", + "stock_analytic", + "procurement_mto_analytic", + ], "data": ["views/rma_order_line_view.xml"], "installable": True, } diff --git a/rma_analytic/models/__init__.py b/rma_analytic/models/__init__.py index fa41cc2bc..9fff87db0 100644 --- a/rma_analytic/models/__init__.py +++ b/rma_analytic/models/__init__.py @@ -1,4 +1,2 @@ -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). - from . import rma_order_line -from . import procurement +from . import stock_rule diff --git a/rma_analytic/models/procurement.py b/rma_analytic/models/procurement.py deleted file mode 100644 index ee3188c2b..000000000 --- a/rma_analytic/models/procurement.py +++ /dev/null @@ -1,22 +0,0 @@ -# © 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("account_analytic_id") - def check_analytic(self): - for order in self: - if order.rma_line_id and ( - order.account_analytic_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 dd29ce2fa..f07700965 100644 --- a/rma_analytic/models/rma_order_line.py +++ b/rma_analytic/models/rma_order_line.py @@ -1,7 +1,7 @@ -# © 2018 Eficent Business and IT Consulting Services S.L. +# Copyright 2023 ForgeFlow 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): @@ -13,9 +13,8 @@ class RmaOrderLine(models.Model): 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) + if line.analytic_account_id: + res.update(analytic_account_id=line.analytic_account_id.id) return res diff --git a/rma_analytic/models/stock_rule.py b/rma_analytic/models/stock_rule.py new file mode 100644 index 000000000..687391f61 --- /dev/null +++ b/rma_analytic/models/stock_rule.py @@ -0,0 +1,33 @@ +# Copyright (C) 2017-22 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from odoo import models + + +class StockRule(models.Model): + _inherit = "stock.rule" + + def _get_stock_move_values( + self, + product_id, + product_qty, + product_uom, + location_id, + name, + origin, + company_id, + values, + ): + res = super()._get_stock_move_values( + product_id, + product_qty, + product_uom, + location_id, + name, + origin, + company_id, + values, + ) + if "analytic_account_id" in values: + res["analytic_account_id"] = values.get("analytic_account_id") + return res diff --git a/rma_analytic/tests/__init__.py b/rma_analytic/tests/__init__.py index e3e7b7fa6..6e6f69657 100644 --- a/rma_analytic/tests/__init__.py +++ b/rma_analytic/tests/__init__.py @@ -1,3 +1 @@ -# © 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 f18ea2ef9..2f9e00879 100644 --- a/rma_analytic/tests/test_rma_analytic.py +++ b/rma_analytic/tests/test_rma_analytic.py @@ -1,6 +1,9 @@ -# © 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2017-23 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +from odoo import fields +from odoo.tests import Form + from odoo.addons.rma.tests import test_rma @@ -8,45 +11,65 @@ class TestRmaAnalytic(test_rma.TestRma): @classmethod def setUpClass(cls): super(TestRmaAnalytic, cls).setUpClass() - cls.rma_add_invoice_wiz = cls.env["rma_add_invoice"] + cls.rma_add_invoice_wiz = cls.env["rma_add_account_move"] cls.rma_refund_wiz = cls.env["rma.refund"] + cls.rma_obj = cls.env["rma.order"] + cls.rma_op_obj = cls.env["rma.operation"] + cls.rma_route_cust = cls.env.ref("rma.route_rma_customer") + cls.cust_refund_op = cls.env.ref("rma_account.rma_operation_customer_refund") + cls.rma_group_customer = cls.rma_obj.create( + {"partner_id": cls.partner_id.id, "type": "customer"} + ) + cls.operation_1 = cls.rma_op_obj.create( + { + "code": "TEST", + "name": "Refund and receive", + "type": "customer", + "receipt_policy": "ordered", + "refund_policy": "ordered", + "in_route_id": cls.rma_route_cust.id, + "out_route_id": cls.rma_route_cust.id, + } + ) + cls.product_1.update( + { + "rma_customer_operation_id": cls.operation_1.id, + "rma_supplier_operation_id": cls.cust_refund_op.id, + } + ) 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.company_id = cls.env.user.company_id cls.anal = cls.env["account.analytic.account"].create({"name": "Name"}) - cls.inv_line_1 = cls.env["account.invoice.line"].create( + cls.inv_customer = cls.env["account.move"].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, + "partner_id": cls.partner_id.id, + "move_type": "out_invoice", + "invoice_date": fields.Date.from_string("2023-01-01"), + "currency_id": cls.company_id.currency_id, + "invoice_line_ids": [ + ( + 0, + None, + { + "name": cls.partner_id.name, + "product_id": cls.product_1.id, + "product_uom_id": cls.product_1.uom_id.id, + "quantity": 12.0, + "price_unit": 100.0, + "analytic_account_id": cls.anal.id, + }, + ), + ], } ) @@ -61,49 +84,6 @@ def _prepare_move(cls, product, qty, src, dest, picking_in): res.update({"analytic_account_id": analytic_1.id}) return res - @classmethod - def _create_rma_analytic(cls, products2move, partner): - picking_in = cls._create_picking(partner) - moves = [] - for item in products2move: - move_values = cls._prepare_anal_move( - item[0], - item[1], - cls.stock_location, - cls.customer_location, - picking_in, - cls.analytic_1, - ) - moves.append(cls.env["stock.move"].create(move_values)) - - rma_id = cls.rma_model.create( - { - "reference": "0001", - "type": "customer", - "partner_id": partner.id, - "company_id": cls.env.ref("base.main_company").id, - } - ) - for move in moves: - wizard = cls.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() - - if move.product_id.rma_customer_operation_id: - move.product_id.rma_customer_operation_id.in_route_id = False - move.product_id.categ_id.rma_customer_operation_id = False - move.product_id.rma_customer_operation_id = False - wizard._prepare_rma_line_from_stock_move(move) - cls.line = cls.rma_line_model.create(data) - return rma_id - def test_analytic(self): for line in self.rma_ana_id.rma_line_ids: for move in line.move_ids: @@ -115,31 +95,21 @@ def test_analytic(self): 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() + rma_line_form = Form(self.env["rma.order.line"].with_context(customer=True)) + rma_line_form.partner_id = self.partner_id + rma_line_form.product_id = self.product_1 + rma_line_form.operation_id = self.env.ref("rma.rma_operation_customer_replace") + rma_line_form.in_route_id = self.env.ref("rma.route_rma_customer") + rma_line_form.out_route_id = self.env.ref("rma.route_rma_customer") + rma_line_form.in_warehouse_id = self.env.ref("stock.warehouse0") + rma_line_form.out_warehouse_id = self.env.ref("stock.warehouse0") + rma_line_form.location_id = self.env.ref("stock.stock_location_stock") + rma_line_form.account_move_line_id = self.inv_customer.invoice_line_ids[0] + rma_line_form.uom_id = self.product_1.uom_id + rma_line = rma_line_form.save() self.assertEqual( rma_line.analytic_account_id, - self.inv_line_1.account_analytic_id, + self.inv_customer.invoice_line_ids[0].analytic_account_id, ) def test_invoice_analytic02(self): @@ -159,58 +129,37 @@ def test_invoice_analytic02(self): ) ) 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)]}) + customer=True, + active_ids=[rma_order.id], + active_model="rma.order", + ).create({"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, + self.inv_customer.invoice_line_ids[0].analytic_account_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, - "delivery_policy": "no", - "receipt_policy": "ordered", - "uom_id": self.product_1.uom_id.id, - } - ) + add_inv = self.rma_add_invoice_wiz.with_context( + customer=True, + active_ids=[self.rma_group_customer.id], + active_model="rma.order", + ).create({"line_ids": [(6, 0, self.inv_customer.invoice_line_ids.ids)]}) + add_inv.add_lines() + rma_line = self.rma_group_customer.rma_line_ids.filtered( + lambda r: r.product_id == self.product_1 ) - rma_line._onchange_invoice_line_id() + rma_line._onchange_account_move_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", - } + 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"), + rma_line.mapped("refund_line_ids.analytic_account_id"), ) diff --git a/rma_analytic/views/rma_order_line_view.xml b/rma_analytic/views/rma_order_line_view.xml index 61c098c9a..a6841e647 100644 --- a/rma_analytic/views/rma_order_line_view.xml +++ b/rma_analytic/views/rma_order_line_view.xml @@ -1,5 +1,5 @@ - diff --git a/rma_analytic/wizards/__init__.py b/rma_analytic/wizards/__init__.py index 65f9813ba..58fc8054a 100644 --- a/rma_analytic/wizards/__init__.py +++ b/rma_analytic/wizards/__init__.py @@ -1,7 +1,7 @@ -# © 2018 Eficent Business and IT Consulting Services S.L. +# Copyright 2023 ForgeFlow 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_add_account_move from . import rma_refund diff --git a/rma_analytic/wizards/rma_add_account_move.py b/rma_analytic/wizards/rma_add_account_move.py new file mode 100644 index 000000000..676b2cfd0 --- /dev/null +++ b/rma_analytic/wizards/rma_add_account_move.py @@ -0,0 +1,14 @@ +# Copyright 2023 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) + +from odoo import models + + +class RmaAddAccountMove(models.TransientModel): + _inherit = "rma_add_account_move" + + def _prepare_rma_line_from_inv_line(self, line): + res = super(RmaAddAccountMove, self)._prepare_rma_line_from_inv_line(line) + if line.analytic_account_id: + res.update(analytic_account_id=line.analytic_account_id.id) + return res diff --git a/rma_analytic/wizards/rma_add_invoice.py b/rma_analytic/wizards/rma_add_invoice.py index bef3d6103..e2129d806 100644 --- a/rma_analytic/wizards/rma_add_invoice.py +++ b/rma_analytic/wizards/rma_add_invoice.py @@ -1,4 +1,4 @@ -# © 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2023 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import models @@ -9,6 +9,6 @@ class RmaAddInvoice(models.TransientModel): 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) + if line.analytic_account_id: + res.update(analytic_account_id=line.analytic_account_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 8318713ee..a8a61f6c2 100644 --- a/rma_analytic/wizards/rma_add_stock_move.py +++ b/rma_analytic/wizards/rma_add_stock_move.py @@ -1,14 +1,12 @@ -# © 2018 Eficent Business and IT Consulting Services S.L. +# Copyright 2023 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -from odoo import api, models +from odoo import 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.id) diff --git a/rma_analytic/wizards/rma_make_picking.py b/rma_analytic/wizards/rma_make_picking.py index 46591ceec..6e50002e7 100644 --- a/rma_analytic/wizards/rma_make_picking.py +++ b/rma_analytic/wizards/rma_make_picking.py @@ -1,4 +1,4 @@ -# © 2018 Eficent Business and IT Consulting Services S.L. +# Copyright 2023 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import api, models @@ -6,12 +6,11 @@ class RmaMakePicking(models.TransientModel): _inherit = "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(account_analytic_id=item.line_id.analytic_account_id.id) + procurement_data.update(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 index d6e185182..32eb7cb60 100644 --- a/rma_analytic/wizards/rma_refund.py +++ b/rma_analytic/wizards/rma_refund.py @@ -1,4 +1,4 @@ -# © 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2023 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import api, models @@ -8,8 +8,8 @@ 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) + def prepare_refund_line(self, item): + res = super(RmaRefund, self).prepare_refund_line(item) if item.line_id.analytic_account_id: - res.update(account_analytic_id=item.line_id.analytic_account_id.id) + res.update(analytic_account_id=item.line_id.analytic_account_id.id) return res From 56797b871cc64b07e7f4cb7e5749c58a226c57bb Mon Sep 17 00:00:00 2001 From: AaronHForgeFlow Date: Mon, 30 Oct 2023 15:08:15 +0100 Subject: [PATCH 17/18] [IMP] rma_analytic: black, isort, prettier --- setup/rma_analytic/odoo/addons/rma_analytic | 1 + setup/rma_analytic/setup.py | 6 ++++++ 2 files changed, 7 insertions(+) create mode 120000 setup/rma_analytic/odoo/addons/rma_analytic create mode 100644 setup/rma_analytic/setup.py diff --git a/setup/rma_analytic/odoo/addons/rma_analytic b/setup/rma_analytic/odoo/addons/rma_analytic new file mode 120000 index 000000000..4a1f6b6fe --- /dev/null +++ b/setup/rma_analytic/odoo/addons/rma_analytic @@ -0,0 +1 @@ +../../../../rma_analytic \ No newline at end of file diff --git a/setup/rma_analytic/setup.py b/setup/rma_analytic/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/rma_analytic/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From 8492a3af221f623e11738842989bae8753bd488a Mon Sep 17 00:00:00 2001 From: AaronHForgeFlow Date: Mon, 30 Oct 2023 15:08:32 +0100 Subject: [PATCH 18/18] [MIG] rma_analytic to v16 --- 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 e93bb50ce..5a6331d59 100644 --- a/rma_analytic/__manifest__.py +++ b/rma_analytic/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Analytic Account in RMA", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "author": "ForgeFlow," "Odoo Community Association (OCA)", "license": "AGPL-3", "website": "https://github.com/ForgeFlow/stock-rma",