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