From 18a2199e2ad762a318e27abb7ee2ba18db5a0f6f Mon Sep 17 00:00:00 2001 From: aheficent Date: Wed, 31 Oct 2018 16:23:58 +0100 Subject: [PATCH 01/15] [ADD]account_move_line_rma_order_line v10 --- account_move_line_rma_order_line/README.rst | 66 +++++ account_move_line_rma_order_line/__init__.py | 5 + .../__manifest__.py | 20 ++ .../models/__init__.py | 7 + .../models/account_invoice.py | 29 ++ .../models/account_move.py | 14 + .../models/stock_move.py | 18 ++ .../security/account_security.xml | 10 + .../tests/__init__.py | 5 + .../test_account_move_line_rma_order_line.py | 253 ++++++++++++++++++ .../views/account_move_view.xml | 66 +++++ 11 files changed, 493 insertions(+) create mode 100644 account_move_line_rma_order_line/README.rst create mode 100644 account_move_line_rma_order_line/__init__.py create mode 100644 account_move_line_rma_order_line/__manifest__.py create mode 100644 account_move_line_rma_order_line/models/__init__.py create mode 100644 account_move_line_rma_order_line/models/account_invoice.py create mode 100644 account_move_line_rma_order_line/models/account_move.py create mode 100644 account_move_line_rma_order_line/models/stock_move.py create mode 100644 account_move_line_rma_order_line/security/account_security.xml create mode 100644 account_move_line_rma_order_line/tests/__init__.py create mode 100644 account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py create mode 100644 account_move_line_rma_order_line/views/account_move_view.xml diff --git a/account_move_line_rma_order_line/README.rst b/account_move_line_rma_order_line/README.rst new file mode 100644 index 000000000..d8f62172a --- /dev/null +++ b/account_move_line_rma_order_line/README.rst @@ -0,0 +1,66 @@ +.. image:: https://img.shields.io/badge/license-AGPLv3-blue.svg + :target: https://www.gnu.org/licenses/agpl.html + :alt: License: AGPL-3 + +========================== +Account Move Line RMA Line +========================== + +This module will add the RMA order line to journal items. + +The ultimate goal is to establish the RMA order line as one of the key +fields to reconcile the Goods Received Not Invoiced accrual account. + + +Usage +===== + +The RMA order line will be automatically copied to the journal items. + +* When a supplier invoice is created referencing RMA orders, the + RMA order line will be copied to the corresponding journal item. + +* When a stock move is validated and generates a journal entry, the RMA + order line is copied to the account move line. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/92/9.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. + + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Jordi Ballester Alomar +* Aarón Henríquez Quintana + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/account_move_line_rma_order_line/__init__.py b/account_move_line_rma_order_line/__init__.py new file mode 100644 index 000000000..b33ed7e33 --- /dev/null +++ b/account_move_line_rma_order_line/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/account_move_line_rma_order_line/__manifest__.py b/account_move_line_rma_order_line/__manifest__.py new file mode 100644 index 000000000..922a07495 --- /dev/null +++ b/account_move_line_rma_order_line/__manifest__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Account Move Line Rma Order Line", + "summary": "Introduces the rma order line to the journal items", + "version": "10.0.1.0.0", + "author": "Eficent, " + "Odoo Community Association (OCA)", + "website": "http://www.github.com/OCA/account-financial-tools", + "category": "Generic", + "depends": ["account_accountant", "rma_account"], + "license": "AGPL-3", + "data": [ + "security/account_security.xml", + "views/account_move_view.xml", + ], + 'installable': True, +} diff --git a/account_move_line_rma_order_line/models/__init__.py b/account_move_line_rma_order_line/models/__init__.py new file mode 100644 index 000000000..ce392315b --- /dev/null +++ b/account_move_line_rma_order_line/models/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import account_move +from . import account_invoice +from . import stock_move diff --git a/account_move_line_rma_order_line/models/account_invoice.py b/account_move_line_rma_order_line/models/account_invoice.py new file mode 100644 index 000000000..873090493 --- /dev/null +++ b/account_move_line_rma_order_line/models/account_invoice.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class AccountInvoice(models.Model): + + _inherit = 'account.invoice' + + @api.model + def invoice_line_move_line_get(self): + res = super(AccountInvoice, self).invoice_line_move_line_get() + + invoice_line_model = self.env['account.invoice.line'] + for move_line_dict in res: + if 'invl_id' in move_line_dict: + line = invoice_line_model.browse(move_line_dict['invl_id']) + move_line_dict['rma_line_id'] = line.rma_line_id.id + + return res + + @api.model + def line_get_convert(self, line, part): + res = super(AccountInvoice, self).line_get_convert(line, part) + if line.get('rma_line_id', False): + res['rma_line_id'] = line.get('rma_line_id') + return res diff --git a/account_move_line_rma_order_line/models/account_move.py b/account_move_line_rma_order_line/models/account_move.py new file mode 100644 index 000000000..059d67837 --- /dev/null +++ b/account_move_line_rma_order_line/models/account_move.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class AccountMoveLine(models.Model): + + _inherit = 'account.move.line' + + rma_line_id = fields.Many2one('rma.order.line', + 'Rma Order Line', + ondelete='set null', index=True) diff --git a/account_move_line_rma_order_line/models/stock_move.py b/account_move_line_rma_order_line/models/stock_move.py new file mode 100644 index 000000000..cb064aa38 --- /dev/null +++ b/account_move_line_rma_order_line/models/stock_move.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class StockMove(models.Model): + _inherit = "stock.move" + + @api.model + def _prepare_account_move_line(self, qty, cost, + credit_account_id, debit_account_id): + res = super(StockMove, self)._prepare_account_move_line( + qty, cost, credit_account_id, debit_account_id) + for line in res: + line[2]['rma_line_id'] = self.rma_line_id.id + return res diff --git a/account_move_line_rma_order_line/security/account_security.xml b/account_move_line_rma_order_line/security/account_security.xml new file mode 100644 index 000000000..a26966e72 --- /dev/null +++ b/account_move_line_rma_order_line/security/account_security.xml @@ -0,0 +1,10 @@ + + + + + Rma Order Line in Journal Items + + + + + diff --git a/account_move_line_rma_order_line/tests/__init__.py b/account_move_line_rma_order_line/tests/__init__.py new file mode 100644 index 000000000..f3dc4c5f3 --- /dev/null +++ b/account_move_line_rma_order_line/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent - Jordi Ballester Alomar +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_account_move_line_rma_order_line diff --git a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py new file mode 100644 index 000000000..c3e5ff8ad --- /dev/null +++ b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py @@ -0,0 +1,253 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo.tests import common + + +class TestAccountMoveLineRmaOrderLine(common.SavepointCase): + + @classmethod + def setUpClass(cls): + super(TestAccountMoveLineRmaOrderLine, cls).setUpClass() + cls.rma_model = cls.env['rma.order'] + cls.rma_line_model = cls.env['rma.order.line'] + cls.rma_add_stock_move = cls.env['rma_add_stock_move'] + cls.rma_make_picking = cls.env['rma_make_picking.wizard'] + cls.invoice_model = cls.env['account.invoice'] + cls.stock_picking_model = cls.env['stock.picking'] + cls.invoice_line_model = cls.env['account.invoice.line'] + cls.product_model = cls.env['product.product'] + cls.product_ctg_model = cls.env['product.category'] + cls.acc_type_model = cls.env['account.account.type'] + cls.account_model = cls.env['account.account'] + cls.aml_model = cls.env['account.move.line'] + cls.res_users_model = cls.env['res.users'] + + cls.partner1 = cls.env.ref('base.res_partner_1') + cls.location_stock = cls.env.ref('stock.stock_location_stock') + cls.company = cls.env.ref('base.main_company') + cls.group_rma_user = cls.env.ref('rma.group_rma_customer_user') + cls.group_account_invoice = cls.env.ref( + 'account.group_account_invoice') + cls.group_account_manager = cls.env.ref( + 'account.group_account_manager') + cls.stock_location = cls.env.ref('stock.stock_location_stock') + wh = cls.env.ref('stock.warehouse0') + cls.stock_rma_location = wh.lot_rma_id + cls.customer_location = cls.env.ref( + 'stock.stock_location_customers') + cls.supplier_location = cls.env.ref( + 'stock.stock_location_suppliers') + # Create account for Goods Received Not Invoiced + acc_type = cls._create_account_type('equity', 'other') + name = 'Goods Received Not Invoiced' + code = 'grni' + cls.account_grni = cls._create_account( + acc_type, name, code,cls.company) + + # Create account for Cost of Goods Sold + acc_type = cls._create_account_type('expense', 'other') + name = 'Cost of Goods Sold' + code = 'cogs' + cls.account_cogs = cls._create_account( + acc_type, name, code, cls.company) + # Create account for Inventory + acc_type = cls._create_account_type('asset', 'other') + name = 'Inventory' + code = 'inventory' + cls.account_inventory = cls._create_account( + acc_type, name, code, cls.company) + # Create Product + cls.product = cls._create_product() + cls.product_uom_id = cls.env.ref('product.product_uom_unit') + # Create users + cls.rma_user = cls._create_user( + 'rma_user', [cls.group_rma_user, + cls.group_account_invoice], cls.company) + cls.account_invoice = cls._create_user( + 'account_invoice', [cls.group_account_invoice], cls.company) + cls.account_manager = cls._create_user( + 'account_manager', [cls.group_account_manager], cls.company) + + @classmethod + def _create_user(cls, login, groups, company): + """ Create a user.""" + group_ids = [group.id for group in groups] + user = \ + cls.res_users_model.with_context( + {'no_reset_password': True}).create({ + 'name': 'Test User', + 'login': login, + 'password': 'demo', + 'email': 'test@yourcompany.com', + 'company_id': company.id, + 'company_ids': [(4, company.id)], + 'groups_id': [(6, 0, group_ids)] + }) + return user.id + + @classmethod + def _create_account_type(cls, name, type): + acc_type = cls.acc_type_model.create({ + 'name': name, + 'type': type + }) + return acc_type + + @classmethod + def _create_account(cls, acc_type, name, code, company): + """Create an account.""" + account = cls.account_model.create({ + 'name': name, + 'code': code, + 'user_type_id': acc_type.id, + 'company_id': company.id + }) + return account + + @classmethod + def _create_product(cls): + """Create a Product.""" + # group_ids = [group.id for group in groups] + product_ctg = cls.product_ctg_model.create({ + 'name': 'test_product_ctg', + 'property_stock_valuation_account_id': cls.account_inventory.id, + 'property_valuation': 'real_time', + 'property_stock_account_input_categ_id': cls.account_grni.id, + 'property_stock_account_output_categ_id': cls.account_cogs.id, + }) + product = cls.product_model.create({ + 'name': 'test_product', + 'categ_id': product_ctg.id, + 'type': 'product', + 'standard_price': 1.0, + 'list_price': 1.0, + }) + return product + + @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.supplier_location.id + }) + + @classmethod + def _prepare_move(cls, product, qty, src, dest, picking_in): + res = { + 'partner_id': cls.partner1.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 + } + return res + + @classmethod + def _create_rma(cls, products2move, partner): + picking_in = cls._create_picking(partner) + moves = [] + for item in products2move: + move_values = cls._prepare_move( + item[0], item[1], cls.stock_location, + cls.customer_location, picking_in) + 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() + + 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) + cls.line = cls.rma_line_model.create(data) + return rma_id + + def _get_balance(self, domain): + """ + Call read_group method and return the balance of particular account. + """ + aml_rec = self.aml_model.read_group( + domain, ['debit', 'credit', 'account_id'], ['account_id']) + if aml_rec: + return aml_rec[0].get('debit', 0) - aml_rec[0].get('credit', 0) + else: + return 0.0 + + def _check_account_balance(self, account_id, rma_line=None, + expected_balance=0.0): + """ + Check the balance of the account + """ + domain = [('account_id', '=', account_id)] + if rma_line: + domain.extend([('rma_line_id', '=', rma_line.id)]) + + balance = self._get_balance(domain) + if rma_line: + self.assertEqual(balance, expected_balance, + 'Balance is not %s for rma Line %s.' + % (str(expected_balance), rma_line.name)) + + def test_rma_invoice(self): + """Test that the rma line moves from the rma order to the + account move line and to the invoice line. + """ + products2move = [(self.product, 1), ] + rma = self._create_rma(products2move, self.partner1) + rma_line = rma.rma_line_ids[0] + rma_line.action_rma_approve() + wizard = self.rma_make_picking.with_context({ + 'active_id': 1, + 'active_ids': rma.rma_line_ids.ids, + 'active_model': 'rma.order.line', + 'picking_type': 'incoming', + }).create({}) + procurements = wizard._create_picking() + group_ids = set([proc.group_id.id for proc in procurements if + proc.group_id]) + domain = [('group_id', 'in', list(group_ids))] + picking = self.stock_picking_model.search(domain) + picking.action_assign() + picking.do_transfer() + + expected_balance = 1.0 + self._check_account_balance(self.account_inventory.id, + rma_line=rma_line, + expected_balance=expected_balance) + + invoice = self.invoice_model.create({ + 'partner_id': self.partner1.id, + 'rma_id': rma.id, + 'account_id': rma.partner_id.property_account_payable_id.id, + }) + invoice.signal_workflow('invoice_open') + + for aml in invoice.move_id.line_ids: + if aml.product_id == rma_line.product_id and aml.invoice_id: + self.assertEqual(aml.rma_line_id, rma_line, + 'Rma Order line has not been copied ' + 'from the invoice to the account move line.') diff --git a/account_move_line_rma_order_line/views/account_move_view.xml b/account_move_line_rma_order_line/views/account_move_view.xml new file mode 100644 index 000000000..1cd45d6dc --- /dev/null +++ b/account_move_line_rma_order_line/views/account_move_view.xml @@ -0,0 +1,66 @@ + + + + + account.move.line.form + account.move.line + + + + + + + + + + account.move.line.form2 + account.move.line + + + + + + + + + + account.move.line.tree + account.move.line + + + + + + + + + + Journal Items + account.move.line + + + + + + + + + + + account.move.form + account.move + + + + + + + + + From e0fa2d9826864e1590e066e9310a5dc9cc9e7225 Mon Sep 17 00:00:00 2001 From: aheficent Date: Tue, 6 Nov 2018 18:35:46 +0100 Subject: [PATCH 02/15] [MIG]account_move_line_rma_order_line to v11 --- account_move_line_rma_order_line/__init__.py | 4 -- .../__manifest__.py | 5 +- .../models/__init__.py | 4 -- .../models/account_invoice.py | 1 - .../models/account_move.py | 1 - .../models/stock_move.py | 5 +- .../security/account_security.xml | 2 +- .../tests/__init__.py | 4 -- .../test_account_move_line_rma_order_line.py | 58 +++++++++++-------- .../views/account_move_view.xml | 12 ---- 10 files changed, 39 insertions(+), 57 deletions(-) diff --git a/account_move_line_rma_order_line/__init__.py b/account_move_line_rma_order_line/__init__.py index b33ed7e33..0650744f6 100644 --- a/account_move_line_rma_order_line/__init__.py +++ b/account_move_line_rma_order_line/__init__.py @@ -1,5 +1 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - from . import models diff --git a/account_move_line_rma_order_line/__manifest__.py b/account_move_line_rma_order_line/__manifest__.py index 922a07495..1d1f37b58 100644 --- a/account_move_line_rma_order_line/__manifest__.py +++ b/account_move_line_rma_order_line/__manifest__.py @@ -1,16 +1,15 @@ -# -*- coding: utf-8 -*- # © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "Account Move Line Rma Order Line", "summary": "Introduces the rma order line to the journal items", - "version": "10.0.1.0.0", + "version": "11.0.1.0.0", "author": "Eficent, " "Odoo Community Association (OCA)", "website": "http://www.github.com/OCA/account-financial-tools", "category": "Generic", - "depends": ["account_accountant", "rma_account"], + "depends": ["account", "rma_account"], "license": "AGPL-3", "data": [ "security/account_security.xml", diff --git a/account_move_line_rma_order_line/models/__init__.py b/account_move_line_rma_order_line/models/__init__.py index ce392315b..84bbffd36 100644 --- a/account_move_line_rma_order_line/models/__init__.py +++ b/account_move_line_rma_order_line/models/__init__.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - from . import account_move from . import account_invoice from . import stock_move diff --git a/account_move_line_rma_order_line/models/account_invoice.py b/account_move_line_rma_order_line/models/account_invoice.py index 873090493..7c3cd6e2d 100644 --- a/account_move_line_rma_order_line/models/account_invoice.py +++ b/account_move_line_rma_order_line/models/account_invoice.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). diff --git a/account_move_line_rma_order_line/models/account_move.py b/account_move_line_rma_order_line/models/account_move.py index 059d67837..f47a8a388 100644 --- a/account_move_line_rma_order_line/models/account_move.py +++ b/account_move_line_rma_order_line/models/account_move.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). diff --git a/account_move_line_rma_order_line/models/stock_move.py b/account_move_line_rma_order_line/models/stock_move.py index cb064aa38..5e3117db5 100644 --- a/account_move_line_rma_order_line/models/stock_move.py +++ b/account_move_line_rma_order_line/models/stock_move.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). @@ -14,5 +13,7 @@ def _prepare_account_move_line(self, qty, cost, res = super(StockMove, self)._prepare_account_move_line( qty, cost, credit_account_id, debit_account_id) for line in res: - line[2]['rma_line_id'] = self.rma_line_id.id + if line[2]["account_id"] != self.product_id.categ_id.\ + property_stock_valuation_account_id.id: + line[2]['rma_line_id'] = self.rma_line_id.id return res diff --git a/account_move_line_rma_order_line/security/account_security.xml b/account_move_line_rma_order_line/security/account_security.xml index a26966e72..fbfd890df 100644 --- a/account_move_line_rma_order_line/security/account_security.xml +++ b/account_move_line_rma_order_line/security/account_security.xml @@ -3,7 +3,7 @@ Rma Order Line in Journal Items - + diff --git a/account_move_line_rma_order_line/tests/__init__.py b/account_move_line_rma_order_line/tests/__init__.py index f3dc4c5f3..641042a11 100644 --- a/account_move_line_rma_order_line/tests/__init__.py +++ b/account_move_line_rma_order_line/tests/__init__.py @@ -1,5 +1 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent - Jordi Ballester Alomar -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - from . import test_account_move_line_rma_order_line diff --git a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py index c3e5ff8ad..d192ecbc0 100644 --- a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py +++ b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). @@ -12,6 +11,7 @@ def setUpClass(cls): super(TestAccountMoveLineRmaOrderLine, cls).setUpClass() cls.rma_model = cls.env['rma.order'] cls.rma_line_model = cls.env['rma.order.line'] + cls.rma_refund_wiz = cls.env['rma.refund'] cls.rma_add_stock_move = cls.env['rma_add_stock_move'] cls.rma_make_picking = cls.env['rma_make_picking.wizard'] cls.invoice_model = cls.env['account.invoice'] @@ -44,7 +44,7 @@ def setUpClass(cls): name = 'Goods Received Not Invoiced' code = 'grni' cls.account_grni = cls._create_account( - acc_type, name, code,cls.company) + acc_type, name, code, cls.company) # Create account for Cost of Goods Sold acc_type = cls._create_account_type('expense', 'other') @@ -169,12 +169,14 @@ def _create_rma(cls, products2move, partner): 'company_id': cls.env.ref('base.main_company').id }) for move in moves: - wizard = cls.rma_add_stock_move.with_context( + wizard = cls.rma_add_stock_move.new( {'stock_move_id': move.id, 'customer': True, 'active_ids': rma_id.id, + 'rma_id': rma_id.id, + 'partner_id': move.partner_id.id, 'active_model': 'rma.order', } - ).create({}) + ) data = wizard._prepare_rma_line_from_stock_move(move) wizard.add_lines() @@ -226,28 +228,34 @@ def test_rma_invoice(self): 'active_model': 'rma.order.line', 'picking_type': 'incoming', }).create({}) - procurements = wizard._create_picking() - group_ids = set([proc.group_id.id for proc in procurements if - proc.group_id]) - domain = [('group_id', 'in', list(group_ids))] - picking = self.stock_picking_model.search(domain) - picking.action_assign() - picking.do_transfer() - - expected_balance = 1.0 - self._check_account_balance(self.account_inventory.id, + operation = self.env['rma.operation'].search( + [('type', '=', 'customer'), + ('refund_policy', '=', 'received')], limit=1) + rma_line.operation_id = operation.id + rma_line.refund_policy = 'received' + + wizard._create_picking() + res = rma_line.action_view_in_shipments() + picking = self.env['stock.picking'].browse(res['res_id']) + picking.move_lines.write({'quantity_done': 1.0}) + picking.button_validate() + # decreasing cogs + expected_balance = -1.0 + self._check_account_balance(self.account_cogs.id, rma_line=rma_line, expected_balance=expected_balance) - - invoice = self.invoice_model.create({ - 'partner_id': self.partner1.id, - 'rma_id': rma.id, - 'account_id': rma.partner_id.property_account_payable_id.id, + make_refund = self.rma_refund_wiz.with_context({ + 'customer': True, + 'active_ids': rma_line.ids, + 'active_model': 'rma.order.line', + }).create({ + 'description': 'Test refund', }) - invoice.signal_workflow('invoice_open') - - for aml in invoice.move_id.line_ids: + make_refund.invoice_refund() + rma_line.refund_line_ids.invoice_id.invoice_validate() + for aml in rma_line.refund_line_ids.invoice_id.move_id.line_ids: if aml.product_id == rma_line.product_id and aml.invoice_id: - self.assertEqual(aml.rma_line_id, rma_line, - 'Rma Order line has not been copied ' - 'from the invoice to the account move line.') + self.assertEqual( + aml.rma_line_id, rma_line, + 'Rma Order line has not been copied from the invoice to ' + 'the account move line.') diff --git a/account_move_line_rma_order_line/views/account_move_view.xml b/account_move_line_rma_order_line/views/account_move_view.xml index 1cd45d6dc..a69aff1dd 100644 --- a/account_move_line_rma_order_line/views/account_move_view.xml +++ b/account_move_line_rma_order_line/views/account_move_view.xml @@ -13,18 +13,6 @@ - - account.move.line.form2 - account.move.line - - - - - - - - account.move.line.tree account.move.line From 1776c4ac03692fe146b4ebf1689365dd8f3bde95 Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Mon, 5 Aug 2019 16:36:41 +0200 Subject: [PATCH 03/15] [MIG]account_move_line_rma_order_line to v12 --- account_move_line_rma_order_line/__manifest__.py | 2 +- .../tests/test_account_move_line_rma_order_line.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/account_move_line_rma_order_line/__manifest__.py b/account_move_line_rma_order_line/__manifest__.py index 1d1f37b58..a45402e0f 100644 --- a/account_move_line_rma_order_line/__manifest__.py +++ b/account_move_line_rma_order_line/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Account Move Line Rma Order Line", "summary": "Introduces the rma order line to the journal items", - "version": "11.0.1.0.0", + "version": "12.0.1.0.0", "author": "Eficent, " "Odoo Community Association (OCA)", "website": "http://www.github.com/OCA/account-financial-tools", diff --git a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py index d192ecbc0..106253c65 100644 --- a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py +++ b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py @@ -60,7 +60,7 @@ def setUpClass(cls): acc_type, name, code, cls.company) # Create Product cls.product = cls._create_product() - cls.product_uom_id = cls.env.ref('product.product_uom_unit') + cls.product_uom_id = cls.env.ref('uom.product_uom_unit') # Create users cls.rma_user = cls._create_user( 'rma_user', [cls.group_rma_user, @@ -252,7 +252,7 @@ def test_rma_invoice(self): 'description': 'Test refund', }) make_refund.invoice_refund() - rma_line.refund_line_ids.invoice_id.invoice_validate() + rma_line.refund_line_ids.invoice_id.action_invoice_open() for aml in rma_line.refund_line_ids.invoice_id.move_id.line_ids: if aml.product_id == rma_line.product_id and aml.invoice_id: self.assertEqual( From 30d2aa1639150f19b85a2bd68ee8bb8073830fc9 Mon Sep 17 00:00:00 2001 From: mreficent Date: Wed, 30 Oct 2019 19:38:23 +0100 Subject: [PATCH 04/15] [FIX] tests --- .../tests/test_account_move_line_rma_order_line.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py index 106253c65..e84d5415f 100644 --- a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py +++ b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py @@ -180,8 +180,8 @@ def _create_rma(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) From 9cd5606df3fdccae976a82f7912c623fb27e0a0b Mon Sep 17 00:00:00 2001 From: Christopher Ormaza Date: Wed, 26 Jan 2022 10:43:55 -0500 Subject: [PATCH 05/15] [14.0][MIG] account_move_line_rma_order_line --- account_move_line_rma_order_line/__init__.py | 9 + .../__manifest__.py | 16 +- .../models/__init__.py | 3 +- .../models/account_invoice.py | 28 -- .../models/account_move.py | 34 +- .../models/stock_move.py | 18 +- .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 4 + .../readme/USAGE.rst | 7 + .../security/account_security.xml | 6 +- .../test_account_move_line_rma_order_line.py | 350 ++++++++++-------- .../views/account_move_view.xml | 54 --- 12 files changed, 258 insertions(+), 272 deletions(-) delete mode 100644 account_move_line_rma_order_line/models/account_invoice.py create mode 100644 account_move_line_rma_order_line/readme/CONTRIBUTORS.rst create mode 100644 account_move_line_rma_order_line/readme/DESCRIPTION.rst create mode 100644 account_move_line_rma_order_line/readme/USAGE.rst delete mode 100644 account_move_line_rma_order_line/views/account_move_view.xml diff --git a/account_move_line_rma_order_line/__init__.py b/account_move_line_rma_order_line/__init__.py index 0650744f6..b49b39ef1 100644 --- a/account_move_line_rma_order_line/__init__.py +++ b/account_move_line_rma_order_line/__init__.py @@ -1 +1,10 @@ from . import models + +import logging +from odoo import api, SUPERUSER_ID + +_logger = logging.getLogger(__name__) + + +def post_init_hook(cr, registry): + api.Environment(cr, SUPERUSER_ID, {}) diff --git a/account_move_line_rma_order_line/__manifest__.py b/account_move_line_rma_order_line/__manifest__.py index a45402e0f..081ddf35d 100644 --- a/account_move_line_rma_order_line/__manifest__.py +++ b/account_move_line_rma_order_line/__manifest__.py @@ -1,19 +1,19 @@ -# © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) +# © 2017-2022 ForgeFlow S.L. (www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "Account Move Line Rma Order Line", "summary": "Introduces the rma order line to the journal items", - "version": "12.0.1.0.0", - "author": "Eficent, " - "Odoo Community Association (OCA)", - "website": "http://www.github.com/OCA/account-financial-tools", + "version": "14.0.1.0.0", + "author": "ForgeFlow, " "Odoo Community Association (OCA)", + "website": "https://github.com/ForgeFlow/stock-rma", "category": "Generic", - "depends": ["account", "rma_account"], + "depends": ["stock_account", "rma_account"], "license": "AGPL-3", "data": [ "security/account_security.xml", - "views/account_move_view.xml", ], - 'installable': True, + "installable": True, + "maintainers": ["ChisOForgeFlow"], + "development_status": "Beta", } diff --git a/account_move_line_rma_order_line/models/__init__.py b/account_move_line_rma_order_line/models/__init__.py index 84bbffd36..4edac2425 100644 --- a/account_move_line_rma_order_line/models/__init__.py +++ b/account_move_line_rma_order_line/models/__init__.py @@ -1,3 +1,2 @@ -from . import account_move -from . import account_invoice from . import stock_move +from . import account_move diff --git a/account_move_line_rma_order_line/models/account_invoice.py b/account_move_line_rma_order_line/models/account_invoice.py deleted file mode 100644 index 7c3cd6e2d..000000000 --- a/account_move_line_rma_order_line/models/account_invoice.py +++ /dev/null @@ -1,28 +0,0 @@ -# © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - -from odoo import api, models - - -class AccountInvoice(models.Model): - - _inherit = 'account.invoice' - - @api.model - def invoice_line_move_line_get(self): - res = super(AccountInvoice, self).invoice_line_move_line_get() - - invoice_line_model = self.env['account.invoice.line'] - for move_line_dict in res: - if 'invl_id' in move_line_dict: - line = invoice_line_model.browse(move_line_dict['invl_id']) - move_line_dict['rma_line_id'] = line.rma_line_id.id - - return res - - @api.model - def line_get_convert(self, line, part): - res = super(AccountInvoice, self).line_get_convert(line, part) - if line.get('rma_line_id', False): - res['rma_line_id'] = line.get('rma_line_id') - return res diff --git a/account_move_line_rma_order_line/models/account_move.py b/account_move_line_rma_order_line/models/account_move.py index f47a8a388..98a91efff 100644 --- a/account_move_line_rma_order_line/models/account_move.py +++ b/account_move_line_rma_order_line/models/account_move.py @@ -1,13 +1,33 @@ -# © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) +# © 2017-2022 ForgeFlow S.L. (www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from odoo import fields, models +from odoo import models -class AccountMoveLine(models.Model): +class AccountMove(models.Model): - _inherit = 'account.move.line' + _inherit = "account.move" - rma_line_id = fields.Many2one('rma.order.line', - 'Rma Order Line', - ondelete='set null', index=True) + def _stock_account_prepare_anglo_saxon_out_lines_vals(self): + product_model = self.env["product.product"] + res = super()._stock_account_prepare_anglo_saxon_out_lines_vals() + for line in res: + if line.get("product_id", False): + product = product_model.browse(line.get("product_id", False)) + if ( + line.get("account_id") + != product.categ_id.property_stock_valuation_account_id.id + ): + current_move = self.browse(line.get("move_id", False)) + current_rma = current_move.invoice_line_ids.filtered( + lambda x: x.rma_line_id and x.product_id.id == product.id + ).mapped("rma_line_id") + if len(current_rma) == 1: + line.update({"rma_line_id": current_rma.id}) + elif len(current_rma) > 1: + find_with_label_rma = current_rma.filtered( + lambda x: x.name == line.get("name") + ) + if len(find_with_label_rma) == 1: + line.update({"rma_line_id": find_with_label_rma.id}) + return res diff --git a/account_move_line_rma_order_line/models/stock_move.py b/account_move_line_rma_order_line/models/stock_move.py index 5e3117db5..39b05b44a 100644 --- a/account_move_line_rma_order_line/models/stock_move.py +++ b/account_move_line_rma_order_line/models/stock_move.py @@ -1,4 +1,4 @@ -# © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) +# © 2017-2022 ForgeFlow S.L. (www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo import api, models @@ -8,12 +8,16 @@ class StockMove(models.Model): _inherit = "stock.move" @api.model - def _prepare_account_move_line(self, qty, cost, - credit_account_id, debit_account_id): + def _prepare_account_move_line( + self, qty, cost, credit_account_id, debit_account_id, description + ): res = super(StockMove, self)._prepare_account_move_line( - qty, cost, credit_account_id, debit_account_id) + qty, cost, credit_account_id, debit_account_id, description + ) for line in res: - if line[2]["account_id"] != self.product_id.categ_id.\ - property_stock_valuation_account_id.id: - line[2]['rma_line_id'] = self.rma_line_id.id + if ( + line[2]["account_id"] + != self.product_id.categ_id.property_stock_valuation_account_id.id + ): + line[2]["rma_line_id"] = self.rma_line_id.id return res diff --git a/account_move_line_rma_order_line/readme/CONTRIBUTORS.rst b/account_move_line_rma_order_line/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..b647a292e --- /dev/null +++ b/account_move_line_rma_order_line/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Christopher Ormaza diff --git a/account_move_line_rma_order_line/readme/DESCRIPTION.rst b/account_move_line_rma_order_line/readme/DESCRIPTION.rst new file mode 100644 index 000000000..d1ae4599c --- /dev/null +++ b/account_move_line_rma_order_line/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This module will add the RMA order line to journal items. + +The ultimate goal is to establish the RMA order line as one of the key +fields to reconcile the Goods Received Not Invoiced accrual account. diff --git a/account_move_line_rma_order_line/readme/USAGE.rst b/account_move_line_rma_order_line/readme/USAGE.rst new file mode 100644 index 000000000..bd5357e84 --- /dev/null +++ b/account_move_line_rma_order_line/readme/USAGE.rst @@ -0,0 +1,7 @@ +The RMA order line will be automatically copied to the journal items. + +* When a supplier invoice is created referencing RMA orders, the + RMA order line will be copied to the corresponding journal item. + +* When a stock move is validated and generates a journal entry, the RMA + order line is copied to the account move line. diff --git a/account_move_line_rma_order_line/security/account_security.xml b/account_move_line_rma_order_line/security/account_security.xml index fbfd890df..ea986f4db 100644 --- a/account_move_line_rma_order_line/security/account_security.xml +++ b/account_move_line_rma_order_line/security/account_security.xml @@ -1,10 +1,10 @@ - + Rma Order Line in Journal Items - - + + diff --git a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py index e84d5415f..3b73b44cc 100644 --- a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py +++ b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py @@ -1,153 +1,154 @@ -# © 2017 Eficent Business and IT Consulting Services S.L. (www.eficent.com) +# © 2017-2022 ForgeFlow S.L. (www.forgeflow.com) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from odoo.tests import common class TestAccountMoveLineRmaOrderLine(common.SavepointCase): - @classmethod def setUpClass(cls): super(TestAccountMoveLineRmaOrderLine, cls).setUpClass() - cls.rma_model = cls.env['rma.order'] - cls.rma_line_model = cls.env['rma.order.line'] - cls.rma_refund_wiz = cls.env['rma.refund'] - cls.rma_add_stock_move = cls.env['rma_add_stock_move'] - cls.rma_make_picking = cls.env['rma_make_picking.wizard'] - cls.invoice_model = cls.env['account.invoice'] - cls.stock_picking_model = cls.env['stock.picking'] - cls.invoice_line_model = cls.env['account.invoice.line'] - cls.product_model = cls.env['product.product'] - cls.product_ctg_model = cls.env['product.category'] - cls.acc_type_model = cls.env['account.account.type'] - cls.account_model = cls.env['account.account'] - cls.aml_model = cls.env['account.move.line'] - cls.res_users_model = cls.env['res.users'] + cls.rma_model = cls.env["rma.order"] + cls.rma_line_model = cls.env["rma.order.line"] + cls.rma_refund_wiz = cls.env["rma.refund"] + cls.rma_add_stock_move = cls.env["rma_add_stock_move"] + cls.rma_make_picking = cls.env["rma_make_picking.wizard"] + cls.invoice_model = cls.env["account.move"] + cls.stock_picking_model = cls.env["stock.picking"] + cls.invoice_line_model = cls.env["account.move.line"] + cls.product_model = cls.env["product.product"] + cls.product_ctg_model = cls.env["product.category"] + cls.acc_type_model = cls.env["account.account.type"] + cls.account_model = cls.env["account.account"] + cls.aml_model = cls.env["account.move.line"] + cls.res_users_model = cls.env["res.users"] - cls.partner1 = cls.env.ref('base.res_partner_1') - cls.location_stock = cls.env.ref('stock.stock_location_stock') - cls.company = cls.env.ref('base.main_company') - cls.group_rma_user = cls.env.ref('rma.group_rma_customer_user') - cls.group_account_invoice = cls.env.ref( - 'account.group_account_invoice') - cls.group_account_manager = cls.env.ref( - 'account.group_account_manager') - cls.stock_location = cls.env.ref('stock.stock_location_stock') - wh = cls.env.ref('stock.warehouse0') + cls.partner1 = cls.env.ref("base.res_partner_1") + cls.location_stock = cls.env.ref("stock.stock_location_stock") + cls.company = cls.env.ref("base.main_company") + cls.group_rma_user = cls.env.ref("rma.group_rma_customer_user") + cls.group_account_invoice = cls.env.ref("account.group_account_invoice") + cls.group_account_manager = cls.env.ref("account.group_account_manager") + cls.stock_location = cls.env.ref("stock.stock_location_stock") + wh = cls.env.ref("stock.warehouse0") cls.stock_rma_location = wh.lot_rma_id - cls.customer_location = cls.env.ref( - 'stock.stock_location_customers') - cls.supplier_location = cls.env.ref( - 'stock.stock_location_suppliers') + cls.customer_location = cls.env.ref("stock.stock_location_customers") + cls.supplier_location = cls.env.ref("stock.stock_location_suppliers") # Create account for Goods Received Not Invoiced - acc_type = cls._create_account_type('equity', 'other') - name = 'Goods Received Not Invoiced' - code = 'grni' - cls.account_grni = cls._create_account( - acc_type, name, code, cls.company) + acc_type = cls._create_account_type("equity", "other", "equity") + name = "Goods Received Not Invoiced" + code = "grni" + cls.account_grni = cls._create_account(acc_type, name, code, cls.company) # Create account for Cost of Goods Sold - acc_type = cls._create_account_type('expense', 'other') - name = 'Cost of Goods Sold' - code = 'cogs' - cls.account_cogs = cls._create_account( - acc_type, name, code, cls.company) + acc_type = cls._create_account_type("expense", "other", "expense") + name = "Cost of Goods Sold" + code = "cogs" + cls.account_cogs = cls._create_account(acc_type, name, code, cls.company) # Create account for Inventory - acc_type = cls._create_account_type('asset', 'other') - name = 'Inventory' - code = 'inventory' - cls.account_inventory = cls._create_account( - acc_type, name, code, cls.company) + acc_type = cls._create_account_type("asset", "other", "asset") + name = "Inventory" + code = "inventory" + cls.account_inventory = cls._create_account(acc_type, name, code, cls.company) # Create Product cls.product = cls._create_product() - cls.product_uom_id = cls.env.ref('uom.product_uom_unit') + cls.product_uom_id = cls.env.ref("uom.product_uom_unit") # Create users cls.rma_user = cls._create_user( - 'rma_user', [cls.group_rma_user, - cls.group_account_invoice], cls.company) + "rma_user", [cls.group_rma_user, cls.group_account_invoice], cls.company + ) cls.account_invoice = cls._create_user( - 'account_invoice', [cls.group_account_invoice], cls.company) + "account_invoice", [cls.group_account_invoice], cls.company + ) cls.account_manager = cls._create_user( - 'account_manager', [cls.group_account_manager], cls.company) + "account_manager", [cls.group_account_manager], cls.company + ) @classmethod def _create_user(cls, login, groups, company): """ Create a user.""" group_ids = [group.id for group in groups] - user = \ - cls.res_users_model.with_context( - {'no_reset_password': True}).create({ - 'name': 'Test User', - 'login': login, - 'password': 'demo', - 'email': 'test@yourcompany.com', - 'company_id': company.id, - 'company_ids': [(4, company.id)], - 'groups_id': [(6, 0, group_ids)] - }) + user = cls.res_users_model.with_context({"no_reset_password": True}).create( + { + "name": "Test User", + "login": login, + "password": "demo", + "email": "test@yourcompany.com", + "company_id": company.id, + "company_ids": [(4, company.id)], + "groups_id": [(6, 0, group_ids)], + } + ) return user.id @classmethod - def _create_account_type(cls, name, type): - acc_type = cls.acc_type_model.create({ - 'name': name, - 'type': type - }) + def _create_account_type(cls, name, type, internal_group): + acc_type = cls.acc_type_model.create( + {"name": name, "type": type, "internal_group": internal_group} + ) return acc_type @classmethod def _create_account(cls, acc_type, name, code, company): """Create an account.""" - account = cls.account_model.create({ - 'name': name, - 'code': code, - 'user_type_id': acc_type.id, - 'company_id': company.id - }) + account = cls.account_model.create( + { + "name": name, + "code": code, + "user_type_id": acc_type.id, + "company_id": company.id, + } + ) return account @classmethod def _create_product(cls): """Create a Product.""" # group_ids = [group.id for group in groups] - product_ctg = cls.product_ctg_model.create({ - 'name': 'test_product_ctg', - 'property_stock_valuation_account_id': cls.account_inventory.id, - 'property_valuation': 'real_time', - 'property_stock_account_input_categ_id': cls.account_grni.id, - 'property_stock_account_output_categ_id': cls.account_cogs.id, - }) - product = cls.product_model.create({ - 'name': 'test_product', - 'categ_id': product_ctg.id, - 'type': 'product', - 'standard_price': 1.0, - 'list_price': 1.0, - }) + product_ctg = cls.product_ctg_model.create( + { + "name": "test_product_ctg", + "property_stock_valuation_account_id": cls.account_inventory.id, + "property_valuation": "real_time", + "property_stock_account_input_categ_id": cls.account_grni.id, + "property_stock_account_output_categ_id": cls.account_cogs.id, + } + ) + product = cls.product_model.create( + { + "name": "test_product", + "categ_id": product_ctg.id, + "type": "product", + "standard_price": 1.0, + "list_price": 1.0, + } + ) return product @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.supplier_location.id - }) + 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.supplier_location.id, + } + ) @classmethod def _prepare_move(cls, product, qty, src, dest, picking_in): res = { - 'partner_id': cls.partner1.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 + "partner_id": cls.partner1.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, } return res @@ -157,35 +158,36 @@ def _create_rma(cls, products2move, partner): moves = [] for item in products2move: move_values = cls._prepare_move( - item[0], item[1], cls.stock_location, - cls.customer_location, picking_in) - moves.append(cls.env['stock.move'].create(move_values)) + item[0], item[1], cls.stock_location, cls.customer_location, picking_in + ) + 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.new( - {'stock_move_id': move.id, 'customer': True, - 'active_ids': rma_id.id, - 'rma_id': rma_id.id, - 'partner_id': move.partner_id.id, - 'active_model': 'rma.order', - } + { + "move_ids": [(6, 0, move.ids)], + "rma_id": rma_id.id, + "partner_id": move.partner_id.id, + } ) - data = wizard._prepare_rma_line_from_stock_move(move) + # 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) + # CHECK ME: this code duplicate rma lines, what is the porpourse? + # 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 _get_balance(self, domain): @@ -193,69 +195,91 @@ def _get_balance(self, domain): Call read_group method and return the balance of particular account. """ aml_rec = self.aml_model.read_group( - domain, ['debit', 'credit', 'account_id'], ['account_id']) + domain, ["debit", "credit", "account_id"], ["account_id"] + ) if aml_rec: - return aml_rec[0].get('debit', 0) - aml_rec[0].get('credit', 0) + return aml_rec[0].get("debit", 0) - aml_rec[0].get("credit", 0) else: return 0.0 - def _check_account_balance(self, account_id, rma_line=None, - expected_balance=0.0): + def _check_account_balance(self, account_id, rma_line=None, expected_balance=0.0): """ Check the balance of the account """ - domain = [('account_id', '=', account_id)] + domain = [("account_id", "=", account_id)] if rma_line: - domain.extend([('rma_line_id', '=', rma_line.id)]) + domain.extend([("rma_line_id", "=", rma_line.id)]) balance = self._get_balance(domain) if rma_line: - self.assertEqual(balance, expected_balance, - 'Balance is not %s for rma Line %s.' - % (str(expected_balance), rma_line.name)) + self.assertEqual( + balance, + expected_balance, + "Balance is not %s for rma Line %s." + % (str(expected_balance), rma_line.name), + ) def test_rma_invoice(self): """Test that the rma line moves from the rma order to the account move line and to the invoice line. """ - products2move = [(self.product, 1), ] + products2move = [ + (self.product, 1), + ] rma = self._create_rma(products2move, self.partner1) - rma_line = rma.rma_line_ids[0] + rma_line = rma.rma_line_ids rma_line.action_rma_approve() - wizard = self.rma_make_picking.with_context({ - 'active_id': 1, - 'active_ids': rma.rma_line_ids.ids, - 'active_model': 'rma.order.line', - 'picking_type': 'incoming', - }).create({}) - operation = self.env['rma.operation'].search( - [('type', '=', 'customer'), - ('refund_policy', '=', 'received')], limit=1) - rma_line.operation_id = operation.id - rma_line.refund_policy = 'received' + wizard = self.rma_make_picking.with_context( + { + "active_id": 1, + "active_ids": rma_line.ids, + "active_model": "rma.order.line", + "picking_type": "incoming", + } + ).create({}) + operation = self.env["rma.operation"].search( + [("type", "=", "customer"), ("refund_policy", "=", "received")], limit=1 + ) + rma_line.write({"operation_id": operation.id}) + rma_line.write({"refund_policy": "received"}) wizard._create_picking() res = rma_line.action_view_in_shipments() - picking = self.env['stock.picking'].browse(res['res_id']) - picking.move_lines.write({'quantity_done': 1.0}) + if "res_id" in res: + picking = self.env["stock.picking"].browse(res["res_id"]) + else: + picking_ids = self.env["stock.picking"].search(res["domain"]) + picking = self.env["stock.picking"].browse(picking_ids) + picking.move_lines.write({"quantity_done": 1.0}) picking.button_validate() # decreasing cogs expected_balance = -1.0 - self._check_account_balance(self.account_cogs.id, - rma_line=rma_line, - expected_balance=expected_balance) - make_refund = self.rma_refund_wiz.with_context({ - 'customer': True, - 'active_ids': rma_line.ids, - 'active_model': 'rma.order.line', - }).create({ - 'description': 'Test refund', - }) + for record in rma_line: + self._check_account_balance( + self.account_cogs.id, rma_line=record, expected_balance=expected_balance + ) + 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() - rma_line.refund_line_ids.invoice_id.action_invoice_open() - for aml in rma_line.refund_line_ids.invoice_id.move_id.line_ids: - if aml.product_id == rma_line.product_id and aml.invoice_id: + rma_line.refund_line_ids.move_id.filtered( + lambda x: x.state != "posted" + ).action_post() + for aml in rma_line.refund_line_ids.move_id.filtered( + lambda x: x.move_type in ("out_refund", "in_refund") + ).invoice_line_ids: + if aml.product_id == rma_line.product_id and aml.move_id: self.assertEqual( - aml.rma_line_id, rma_line, - 'Rma Order line has not been copied from the invoice to ' - 'the account move line.') + aml.rma_line_id, + rma_line, + "Rma Order line has not been copied from the invoice to " + "the account move line.", + ) diff --git a/account_move_line_rma_order_line/views/account_move_view.xml b/account_move_line_rma_order_line/views/account_move_view.xml deleted file mode 100644 index a69aff1dd..000000000 --- a/account_move_line_rma_order_line/views/account_move_view.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - account.move.line.form - account.move.line - - - - - - - - - - account.move.line.tree - account.move.line - - - - - - - - - - Journal Items - account.move.line - - - - - - - - - - - account.move.form - account.move - - - - - - - - - From d50fbfe7d0601e41a7d6e828cd08eb958c6922b5 Mon Sep 17 00:00:00 2001 From: Christopher Ormaza Date: Fri, 28 Jan 2022 10:23:09 -0500 Subject: [PATCH 06/15] IMP: added init hook --- account_move_line_rma_order_line/__init__.py | 33 ++++++++++++++++++- .../__manifest__.py | 1 + .../test_account_move_line_rma_order_line.py | 9 +++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/account_move_line_rma_order_line/__init__.py b/account_move_line_rma_order_line/__init__.py index b49b39ef1..0ab02f928 100644 --- a/account_move_line_rma_order_line/__init__.py +++ b/account_move_line_rma_order_line/__init__.py @@ -7,4 +7,35 @@ def post_init_hook(cr, registry): - api.Environment(cr, SUPERUSER_ID, {}) + env = api.Environment(cr, SUPERUSER_ID, {}) + aml_model = env["account.move.line"] + sm_model = env["stock.move"] + svl_model = env["stock.valuation.layer"] + aml_moves = aml_model.search([("rma_line_id", "!=", False)]) + sm_moves = sm_model.search([("rma_line_id", "!=", False)]) + for account_move in aml_moves.mapped("move_id"): + for aml_w_rma in account_move.invoice_line_ids.filtered( + lambda x: x.product_id + and x.account_id.id + != x.product_id.categ_id.property_stock_valuation_account_id.id + and x.rma_line_id + ): + invoice_lines_without_rma = account_move.invoice_line_ids.filtered( + lambda x: x.product_id.id == aml_w_rma.product_id.id + and not x.rma_line_id + and aml_w_rma.name in x.name + ) + if invoice_lines_without_rma: + invoice_lines_without_rma.write( + { + "rma_line_id": aml_w_rma.rma_line_id.id, + } + ) + for move in sm_moves: + current_layers = svl_model.search([("stock_move_id", "=", move.id)]) + if current_layers: + for aml in current_layers.mapped("account_move_id.line_ids").filtered( + lambda x: x.account_id.id + != move.product_id.categ_id.property_stock_valuation_account_id.id + ): + aml.rma_line_id = move.rma_line_id.id diff --git a/account_move_line_rma_order_line/__manifest__.py b/account_move_line_rma_order_line/__manifest__.py index 081ddf35d..b8556c828 100644 --- a/account_move_line_rma_order_line/__manifest__.py +++ b/account_move_line_rma_order_line/__manifest__.py @@ -16,4 +16,5 @@ "installable": True, "maintainers": ["ChisOForgeFlow"], "development_status": "Beta", + "post_init_hook": "post_init_hook", } diff --git a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py index 3b73b44cc..936c75e80 100644 --- a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py +++ b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py @@ -228,6 +228,9 @@ def test_rma_invoice(self): ] rma = self._create_rma(products2move, self.partner1) rma_line = rma.rma_line_ids + for rma in rma_line: + if rma.price_unit == 0: + rma.price_unit = 1.0 rma_line.action_rma_approve() wizard = self.rma_make_picking.with_context( { @@ -269,6 +272,12 @@ def test_rma_invoice(self): "description": "Test refund", } ) + for item in make_refund.item_ids: + item.write( + { + "qty_to_refund": 1.0, + } + ) make_refund.invoice_refund() rma_line.refund_line_ids.move_id.filtered( lambda x: x.state != "posted" From a6f2e5c3d79f7fc7e73a8662fd37075049cdd7b7 Mon Sep 17 00:00:00 2001 From: Jordi Ballester Date: Wed, 2 Mar 2022 11:35:08 +0100 Subject: [PATCH 07/15] [IMP] rma: Refactor all rma modules in order to consider using the correct price unit in moves Otherwise the inventory accounting will be completely wrong. --- .../tests/test_account_move_line_rma_order_line.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py index 936c75e80..5b38e5fd7 100644 --- a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py +++ b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py @@ -279,10 +279,10 @@ def test_rma_invoice(self): } ) make_refund.invoice_refund() - rma_line.refund_line_ids.move_id.filtered( + rma_line.move_line_ids.move_id.filtered( lambda x: x.state != "posted" ).action_post() - for aml in rma_line.refund_line_ids.move_id.filtered( + for aml in rma_line.move_line_ids.move_id.filtered( lambda x: x.move_type in ("out_refund", "in_refund") ).invoice_line_ids: if aml.product_id == rma_line.product_id and aml.move_id: From f3bf3f3b3fbc29133e7f9b01c0fdad0355cbfde4 Mon Sep 17 00:00:00 2001 From: Jordi Ballester Date: Wed, 2 Mar 2022 13:11:20 +0100 Subject: [PATCH 08/15] [FIX] rma_account: maintain refund_line_id --- .../tests/test_account_move_line_rma_order_line.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py index 5b38e5fd7..766c1ba43 100644 --- a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py +++ b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py @@ -279,12 +279,10 @@ def test_rma_invoice(self): } ) make_refund.invoice_refund() - rma_line.move_line_ids.move_id.filtered( + rma_line.refund_line_ids.move_id.filtered( lambda x: x.state != "posted" ).action_post() - for aml in rma_line.move_line_ids.move_id.filtered( - lambda x: x.move_type in ("out_refund", "in_refund") - ).invoice_line_ids: + for aml in rma_line.refund_line_ids.move_id.invoice_line_ids: if aml.product_id == rma_line.product_id and aml.move_id: self.assertEqual( aml.rma_line_id, From 86fadeb4385fcd148640f9d6aa68804c2b0d0dc8 Mon Sep 17 00:00:00 2001 From: Jordi Ballester Date: Wed, 2 Mar 2022 14:51:41 +0100 Subject: [PATCH 09/15] [FIX] account_move_line_rma_order_line: Force to trigger again the init hook. As the script was incorrect in previous versions. --- account_move_line_rma_order_line/__init__.py | 9 +++++---- account_move_line_rma_order_line/__manifest__.py | 2 +- .../migrations/14.0.1.1.0/post-migration.py | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 account_move_line_rma_order_line/migrations/14.0.1.1.0/post-migration.py diff --git a/account_move_line_rma_order_line/__init__.py b/account_move_line_rma_order_line/__init__.py index 0ab02f928..e7cb8a0c7 100644 --- a/account_move_line_rma_order_line/__init__.py +++ b/account_move_line_rma_order_line/__init__.py @@ -14,19 +14,19 @@ def post_init_hook(cr, registry): aml_moves = aml_model.search([("rma_line_id", "!=", False)]) sm_moves = sm_model.search([("rma_line_id", "!=", False)]) for account_move in aml_moves.mapped("move_id"): - for aml_w_rma in account_move.invoice_line_ids.filtered( + for aml_w_rma in account_move.line_ids.filtered( lambda x: x.product_id and x.account_id.id != x.product_id.categ_id.property_stock_valuation_account_id.id and x.rma_line_id ): - invoice_lines_without_rma = account_move.invoice_line_ids.filtered( + move_lines_without_rma = account_move.line_ids.filtered( lambda x: x.product_id.id == aml_w_rma.product_id.id and not x.rma_line_id and aml_w_rma.name in x.name ) - if invoice_lines_without_rma: - invoice_lines_without_rma.write( + if move_lines_without_rma: + move_lines_without_rma.write( { "rma_line_id": aml_w_rma.rma_line_id.id, } @@ -37,5 +37,6 @@ def post_init_hook(cr, registry): for aml in current_layers.mapped("account_move_id.line_ids").filtered( lambda x: x.account_id.id != move.product_id.categ_id.property_stock_valuation_account_id.id + and not x.rma_line_id ): aml.rma_line_id = move.rma_line_id.id diff --git a/account_move_line_rma_order_line/__manifest__.py b/account_move_line_rma_order_line/__manifest__.py index b8556c828..285f3c1db 100644 --- a/account_move_line_rma_order_line/__manifest__.py +++ b/account_move_line_rma_order_line/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Account Move Line Rma Order Line", "summary": "Introduces the rma order line to the journal items", - "version": "14.0.1.0.0", + "version": "14.0.1.1.0", "author": "ForgeFlow, " "Odoo Community Association (OCA)", "website": "https://github.com/ForgeFlow/stock-rma", "category": "Generic", diff --git a/account_move_line_rma_order_line/migrations/14.0.1.1.0/post-migration.py b/account_move_line_rma_order_line/migrations/14.0.1.1.0/post-migration.py new file mode 100644 index 000000000..0ecd26e33 --- /dev/null +++ b/account_move_line_rma_order_line/migrations/14.0.1.1.0/post-migration.py @@ -0,0 +1,15 @@ +# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com) +# Part of ForgeFlow. See LICENSE file for full copyright and licensing details. +import logging + +from odoo import SUPERUSER_ID, api + +from odoo.addons.account_move_line_rma_order_line import post_init_hook + +_logger = logging.getLogger(__name__) + + +def migrate(cr, version): + _logger.info("Trigger again the post_init_hook") + env = api.Environment(cr, SUPERUSER_ID, {}) + post_init_hook(cr, env.registry) From 2e98a1c3f7c4ddd1beef5308c8eb9842b13db991 Mon Sep 17 00:00:00 2001 From: AaronHForgeFlow Date: Fri, 22 Apr 2022 11:18:24 +0200 Subject: [PATCH 10/15] [IMP] account_move_line_rma_order_line: cosmetics because of update copier template --- .../tests/test_account_move_line_rma_order_line.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py index 766c1ba43..8907d16d6 100644 --- a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py +++ b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py @@ -66,7 +66,7 @@ def setUpClass(cls): @classmethod def _create_user(cls, login, groups, company): - """ Create a user.""" + """Create a user.""" group_ids = [group.id for group in groups] user = cls.res_users_model.with_context({"no_reset_password": True}).create( { @@ -82,9 +82,9 @@ def _create_user(cls, login, groups, company): return user.id @classmethod - def _create_account_type(cls, name, type, internal_group): + def _create_account_type(cls, name, atype, internal_group): acc_type = cls.acc_type_model.create( - {"name": name, "type": type, "internal_group": internal_group} + {"name": name, "type": atype, "internal_group": internal_group} ) return acc_type From 95147bc76b3fc518d6a711b3a6cb402b53d53f66 Mon Sep 17 00:00:00 2001 From: AaronHForgeFlow Date: Fri, 4 Mar 2022 10:56:07 +0100 Subject: [PATCH 11/15] [FIX] rma: rma_custmer_user has no write permissions in partner, so compute method fails. [IMP] rma: use rma user in tests [FIX] rma_account: move_line_id field string [IMP] rma, rma_account, rma_sale, rma_purchase: tests for stock valuation [FIX] account_move_line_rma_order_line: minor lint, make auto-install [IMP] rma_account_unreconciled: use manager user in test --- account_move_line_rma_order_line/__manifest__.py | 1 + .../tests/test_account_move_line_rma_order_line.py | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/account_move_line_rma_order_line/__manifest__.py b/account_move_line_rma_order_line/__manifest__.py index 285f3c1db..77666408d 100644 --- a/account_move_line_rma_order_line/__manifest__.py +++ b/account_move_line_rma_order_line/__manifest__.py @@ -17,4 +17,5 @@ "maintainers": ["ChisOForgeFlow"], "development_status": "Beta", "post_init_hook": "post_init_hook", + "auto_install": True, } diff --git a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py index 8907d16d6..7f564cf50 100644 --- a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py +++ b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py @@ -82,14 +82,14 @@ def _create_user(cls, login, groups, company): return user.id @classmethod - def _create_account_type(cls, name, atype, internal_group): + def _create_account_type(cls, name, account_type, internal_group): acc_type = cls.acc_type_model.create( - {"name": name, "type": atype, "internal_group": internal_group} + {"name": name, "type": account_type, "internal_group": internal_group} ) return acc_type @classmethod - def _create_account(cls, acc_type, name, code, company): + def _create_account(cls, acc_type, name, code, company, reconcile=False): """Create an account.""" account = cls.account_model.create( { @@ -97,6 +97,7 @@ def _create_account(cls, acc_type, name, code, company): "code": code, "user_type_id": acc_type.id, "company_id": company.id, + "reconcile": reconcile, } ) return account From b11832004a1db8145edcb00a25487c78d5d59767 Mon Sep 17 00:00:00 2001 From: Jordi Ballester Alomar Date: Mon, 21 Nov 2022 15:13:06 +0100 Subject: [PATCH 12/15] [FIX] include anglo-saxon price unit calculation in refunds. Otherwise the anglo saxon entries won't be correct. For example, the Interim (Delivered) account should balance after receiving and triggering a refund on a customer rma. --- .../tests/test_account_move_line_rma_order_line.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py index 7f564cf50..88c3283a1 100644 --- a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py +++ b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py @@ -42,8 +42,8 @@ def setUpClass(cls): # Create account for Cost of Goods Sold acc_type = cls._create_account_type("expense", "other", "expense") - name = "Cost of Goods Sold" - code = "cogs" + name = "Goods Delivered Not Invoiced" + code = "gdni" cls.account_cogs = cls._create_account(acc_type, name, code, cls.company) # Create account for Inventory acc_type = cls._create_account_type("asset", "other", "asset") From 8033ed45f99e0069d51014d80fb605b765e79a5e Mon Sep 17 00:00:00 2001 From: AlexPForgeFlow Date: Tue, 12 Sep 2023 11:55:26 +0200 Subject: [PATCH 13/15] [IMP] account_move_line_rma_order_line: pre-commit stuff --- .../odoo/addons/account_move_line_rma_order_line | 1 + setup/account_move_line_rma_order_line/setup.py | 6 ++++++ 2 files changed, 7 insertions(+) create mode 120000 setup/account_move_line_rma_order_line/odoo/addons/account_move_line_rma_order_line create mode 100644 setup/account_move_line_rma_order_line/setup.py diff --git a/setup/account_move_line_rma_order_line/odoo/addons/account_move_line_rma_order_line b/setup/account_move_line_rma_order_line/odoo/addons/account_move_line_rma_order_line new file mode 120000 index 000000000..5b84b3857 --- /dev/null +++ b/setup/account_move_line_rma_order_line/odoo/addons/account_move_line_rma_order_line @@ -0,0 +1 @@ +../../../../account_move_line_rma_order_line \ No newline at end of file diff --git a/setup/account_move_line_rma_order_line/setup.py b/setup/account_move_line_rma_order_line/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/account_move_line_rma_order_line/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From 3247261086a3dcfd810b1c34741a481d97f48acc Mon Sep 17 00:00:00 2001 From: AlexPForgeFlow Date: Tue, 12 Sep 2023 13:42:11 +0200 Subject: [PATCH 14/15] [MIG] account_move_line_rma_order_line: Migration to 16.0 --- .../__manifest__.py | 2 +- .../migrations/14.0.1.1.0/post-migration.py | 15 ----------- .../models/stock_move.py | 4 +-- .../test_account_move_line_rma_order_line.py | 26 +++++++------------ 4 files changed, 12 insertions(+), 35 deletions(-) delete mode 100644 account_move_line_rma_order_line/migrations/14.0.1.1.0/post-migration.py diff --git a/account_move_line_rma_order_line/__manifest__.py b/account_move_line_rma_order_line/__manifest__.py index 77666408d..01ddade0f 100644 --- a/account_move_line_rma_order_line/__manifest__.py +++ b/account_move_line_rma_order_line/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Account Move Line Rma Order Line", "summary": "Introduces the rma order line to the journal items", - "version": "14.0.1.1.0", + "version": "16.0.1.1.0", "author": "ForgeFlow, " "Odoo Community Association (OCA)", "website": "https://github.com/ForgeFlow/stock-rma", "category": "Generic", diff --git a/account_move_line_rma_order_line/migrations/14.0.1.1.0/post-migration.py b/account_move_line_rma_order_line/migrations/14.0.1.1.0/post-migration.py deleted file mode 100644 index 0ecd26e33..000000000 --- a/account_move_line_rma_order_line/migrations/14.0.1.1.0/post-migration.py +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com) -# Part of ForgeFlow. See LICENSE file for full copyright and licensing details. -import logging - -from odoo import SUPERUSER_ID, api - -from odoo.addons.account_move_line_rma_order_line import post_init_hook - -_logger = logging.getLogger(__name__) - - -def migrate(cr, version): - _logger.info("Trigger again the post_init_hook") - env = api.Environment(cr, SUPERUSER_ID, {}) - post_init_hook(cr, env.registry) diff --git a/account_move_line_rma_order_line/models/stock_move.py b/account_move_line_rma_order_line/models/stock_move.py index 39b05b44a..e2e01bc34 100644 --- a/account_move_line_rma_order_line/models/stock_move.py +++ b/account_move_line_rma_order_line/models/stock_move.py @@ -9,10 +9,10 @@ class StockMove(models.Model): @api.model def _prepare_account_move_line( - self, qty, cost, credit_account_id, debit_account_id, description + self, qty, cost, credit_account_id, debit_account_id, svl_id, description ): res = super(StockMove, self)._prepare_account_move_line( - qty, cost, credit_account_id, debit_account_id, description + qty, cost, credit_account_id, debit_account_id, svl_id, description ) for line in res: if ( diff --git a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py index 88c3283a1..20568bd42 100644 --- a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py +++ b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py @@ -4,7 +4,7 @@ from odoo.tests import common -class TestAccountMoveLineRmaOrderLine(common.SavepointCase): +class TestAccountMoveLineRmaOrderLine(common.TransactionCase): @classmethod def setUpClass(cls): super(TestAccountMoveLineRmaOrderLine, cls).setUpClass() @@ -18,7 +18,6 @@ def setUpClass(cls): cls.invoice_line_model = cls.env["account.move.line"] cls.product_model = cls.env["product.product"] cls.product_ctg_model = cls.env["product.category"] - cls.acc_type_model = cls.env["account.account.type"] cls.account_model = cls.env["account.account"] cls.aml_model = cls.env["account.move.line"] cls.res_users_model = cls.env["res.users"] @@ -35,18 +34,18 @@ def setUpClass(cls): cls.customer_location = cls.env.ref("stock.stock_location_customers") cls.supplier_location = cls.env.ref("stock.stock_location_suppliers") # Create account for Goods Received Not Invoiced - acc_type = cls._create_account_type("equity", "other", "equity") + acc_type = "equity" name = "Goods Received Not Invoiced" code = "grni" cls.account_grni = cls._create_account(acc_type, name, code, cls.company) # Create account for Cost of Goods Sold - acc_type = cls._create_account_type("expense", "other", "expense") + acc_type = "expense" name = "Goods Delivered Not Invoiced" code = "gdni" cls.account_cogs = cls._create_account(acc_type, name, code, cls.company) # Create account for Inventory - acc_type = cls._create_account_type("asset", "other", "asset") + acc_type = "asset_cash" name = "Inventory" code = "inventory" cls.account_inventory = cls._create_account(acc_type, name, code, cls.company) @@ -68,7 +67,7 @@ def setUpClass(cls): def _create_user(cls, login, groups, company): """Create a user.""" group_ids = [group.id for group in groups] - user = cls.res_users_model.with_context({"no_reset_password": True}).create( + user = cls.res_users_model.with_context(**{"no_reset_password": True}).create( { "name": "Test User", "login": login, @@ -81,13 +80,6 @@ def _create_user(cls, login, groups, company): ) return user.id - @classmethod - def _create_account_type(cls, name, account_type, internal_group): - acc_type = cls.acc_type_model.create( - {"name": name, "type": account_type, "internal_group": internal_group} - ) - return acc_type - @classmethod def _create_account(cls, acc_type, name, code, company, reconcile=False): """Create an account.""" @@ -95,7 +87,7 @@ def _create_account(cls, acc_type, name, code, company, reconcile=False): { "name": name, "code": code, - "user_type_id": acc_type.id, + "account_type": acc_type, "company_id": company.id, "reconcile": reconcile, } @@ -234,7 +226,7 @@ def test_rma_invoice(self): rma.price_unit = 1.0 rma_line.action_rma_approve() wizard = self.rma_make_picking.with_context( - { + **{ "active_id": 1, "active_ids": rma_line.ids, "active_model": "rma.order.line", @@ -254,7 +246,7 @@ def test_rma_invoice(self): else: picking_ids = self.env["stock.picking"].search(res["domain"]) picking = self.env["stock.picking"].browse(picking_ids) - picking.move_lines.write({"quantity_done": 1.0}) + picking.move_ids.write({"quantity_done": 1.0}) picking.button_validate() # decreasing cogs expected_balance = -1.0 @@ -263,7 +255,7 @@ def test_rma_invoice(self): self.account_cogs.id, rma_line=record, expected_balance=expected_balance ) make_refund = self.rma_refund_wiz.with_context( - { + **{ "customer": True, "active_ids": rma_line.ids, "active_model": "rma.order.line", From 5193293177eb48c797ebc81ce4dc17cbc51265c7 Mon Sep 17 00:00:00 2001 From: AlexPForgeFlow Date: Thu, 9 May 2024 10:11:46 +0200 Subject: [PATCH 15/15] [FIX] account_move_line_rma_order_line: remove security group group_account_move_rma_order_line + clean up commented code --- account_move_line_rma_order_line/__manifest__.py | 4 +--- .../security/account_security.xml | 10 ---------- .../tests/test_account_move_line_rma_order_line.py | 9 --------- 3 files changed, 1 insertion(+), 22 deletions(-) delete mode 100644 account_move_line_rma_order_line/security/account_security.xml diff --git a/account_move_line_rma_order_line/__manifest__.py b/account_move_line_rma_order_line/__manifest__.py index 01ddade0f..443c256ae 100644 --- a/account_move_line_rma_order_line/__manifest__.py +++ b/account_move_line_rma_order_line/__manifest__.py @@ -10,9 +10,7 @@ "category": "Generic", "depends": ["stock_account", "rma_account"], "license": "AGPL-3", - "data": [ - "security/account_security.xml", - ], + "data": [], "installable": True, "maintainers": ["ChisOForgeFlow"], "development_status": "Beta", diff --git a/account_move_line_rma_order_line/security/account_security.xml b/account_move_line_rma_order_line/security/account_security.xml deleted file mode 100644 index ea986f4db..000000000 --- a/account_move_line_rma_order_line/security/account_security.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Rma Order Line in Journal Items - - - - - diff --git a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py index 20568bd42..4d6328b6a 100644 --- a/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py +++ b/account_move_line_rma_order_line/tests/test_account_move_line_rma_order_line.py @@ -97,7 +97,6 @@ def _create_account(cls, acc_type, name, code, company, reconcile=False): @classmethod def _create_product(cls): """Create a Product.""" - # group_ids = [group.id for group in groups] product_ctg = cls.product_ctg_model.create( { "name": "test_product_ctg", @@ -171,16 +170,8 @@ def _create_rma(cls, products2move, partner): "partner_id": move.partner_id.id, } ) - # data = wizard._prepare_rma_line_from_stock_move(move) wizard.add_lines() - # CHECK ME: this code duplicate rma lines, what is the porpourse? - # 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 _get_balance(self, domain):