From 4ae9689db4d0742170f7ad5f48e1013eff7b643a Mon Sep 17 00:00:00 2001 From: ArnauCForgeFlow Date: Thu, 26 Oct 2023 15:08:00 +0200 Subject: [PATCH] [MIG] account_move_line_repair_info: Migration to 16.0 --- account_move_line_repair_info/README.rst | 12 ++-- account_move_line_repair_info/__manifest__.py | 3 +- .../models/__init__.py | 2 +- .../models/account_move.py | 60 +++++++++---------- .../models/stock_move.py | 39 ------------ .../models/stock_valuation_layer.py | 22 +++++++ .../static/description/index.html | 8 +-- .../test_account_move_line_repair_info.py | 24 +++----- 8 files changed, 69 insertions(+), 101 deletions(-) delete mode 100644 account_move_line_repair_info/models/stock_move.py create mode 100644 account_move_line_repair_info/models/stock_valuation_layer.py diff --git a/account_move_line_repair_info/README.rst b/account_move_line_repair_info/README.rst index 7b6842be9..7a401ebff 100644 --- a/account_move_line_repair_info/README.rst +++ b/account_move_line_repair_info/README.rst @@ -7,7 +7,7 @@ Account Move Line Repair Info !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:501799819b3b4d34a900a1035efbf8ba3a021300c180e1d9e4097cecdf9eabdf + !! source digest: sha256:44a807b48cf561e9c5eb22bd9e1308e78246ab34e9ca623cea3ae9d108f29e80 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -17,13 +17,13 @@ Account Move Line Repair Info :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github - :target: https://github.com/OCA/account-financial-tools/tree/14.0/account_move_line_repair_info + :target: https://github.com/OCA/account-financial-tools/tree/16.0/account_move_line_repair_info :alt: OCA/account-financial-tools .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/account-financial-tools-14-0/account-financial-tools-14-0-account_move_line_repair_info + :target: https://translation.odoo-community.org/projects/account-financial-tools-16-0/account-financial-tools-16-0-account_move_line_repair_info :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png - :target: https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&target_branch=14.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&target_branch=16.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -49,7 +49,7 @@ 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 to smash it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -79,6 +79,6 @@ 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. -This module is part of the `OCA/account-financial-tools `_ project on GitHub. +This module is part of the `OCA/account-financial-tools `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_move_line_repair_info/__manifest__.py b/account_move_line_repair_info/__manifest__.py index bfcfca8e3..e0a1360ac 100644 --- a/account_move_line_repair_info/__manifest__.py +++ b/account_move_line_repair_info/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Account Move Line Repair Info", "summary": "Introduces the repair order to the journal items", - "version": "14.0.1.0.0", + "version": "16.0.1.0.0", "author": "ForgeFlow S.L., " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/account-financial-tools", "category": "Generic", @@ -12,7 +12,6 @@ "account", "repair", "stock_account", - "stock_account_prepare_anglo_saxon_out_lines_hook", ], "license": "AGPL-3", "data": ["security/account_security.xml", "views/account_move_view.xml"], diff --git a/account_move_line_repair_info/models/__init__.py b/account_move_line_repair_info/models/__init__.py index 16528a5e2..a5685dccc 100644 --- a/account_move_line_repair_info/models/__init__.py +++ b/account_move_line_repair_info/models/__init__.py @@ -1,3 +1,3 @@ from . import account_move from . import repair_order -from . import stock_move +from . import stock_valuation_layer diff --git a/account_move_line_repair_info/models/account_move.py b/account_move_line_repair_info/models/account_move.py index facbf1819..cdeab5790 100644 --- a/account_move_line_repair_info/models/account_move.py +++ b/account_move_line_repair_info/models/account_move.py @@ -8,40 +8,34 @@ class AccountMove(models.Model): _inherit = "account.move" - def _prepare_interim_account_line_vals(self, line, move, debit_interim_account): - res = super()._prepare_interim_account_line_vals( - line, move, debit_interim_account - ) - if len(line.repair_line_ids) == 1: - res.update( - { - "repair_order_id": line.repair_line_ids.repair_id.id, - } - ) - if len(line.repair_fee_ids) == 1: - res.update( - { - "repair_order_id": line.repair_fee_ids.repair_id.id, - } - ) - return res - - def _prepare_expense_account_line_vals(self, line, move, debit_interim_account): - res = super()._prepare_expense_account_line_vals( - line, move, debit_interim_account - ) - if len(line.repair_line_ids) == 1: - res.update( - { - "repair_order_id": line.repair_line_ids.repair_id.id, - } - ) - if len(line.repair_fee_ids) == 1: - res.update( - { - "repair_order_id": line.repair_fee_ids.repair_id.id, - } + def _stock_account_prepare_anglo_saxon_out_lines_vals(self): + res = super()._stock_account_prepare_anglo_saxon_out_lines_vals() + for i, vals in enumerate(res): + if ( + not vals.get("move_id", False) + or not vals.get("product_id", False) + or not vals.get("quantity", False) + ): + continue + am = self.env["account.move"].browse(vals["move_id"]) + repair_line = am.invoice_line_ids.filtered( + lambda il: il.product_id.id == vals["product_id"] + and il.quantity == vals["quantity"] ) + repair_order = repair_line.repair_fee_ids.mapped("repair_id") + if len(repair_order) == 1: + res[i].update( + { + "repair_order_id": repair_line.repair_fee_ids.repair_id.id, + } + ) + repair_order = repair_line.repair_line_ids.mapped("repair_id") + if len(repair_order) == 1: + res[i].update( + { + "repair_order_id": repair_line.repair_line_ids.repair_id.id, + } + ) return res @api.model_create_multi diff --git a/account_move_line_repair_info/models/stock_move.py b/account_move_line_repair_info/models/stock_move.py deleted file mode 100644 index 2812848a1..000000000 --- a/account_move_line_repair_info/models/stock_move.py +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright 2022 ForgeFlow S.L. -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - -from odoo import models - - -class StockMove(models.Model): - - _inherit = "stock.move" - - def _create_account_move_line( - self, - credit_account_id, - debit_account_id, - journal_id, - qty, - description, - svl_id, - cost, - ): - am_model = self.env["account.move"] - res = super()._create_account_move_line( - credit_account_id, - debit_account_id, - journal_id, - qty, - description, - svl_id, - cost, - ) - if self.repair_id: - current_move = am_model.search([("stock_move_id", "=", self.id)]) - if current_move: - current_move.line_ids.write( - { - "repair_order_id": self.repair_id.id, - } - ) - return res diff --git a/account_move_line_repair_info/models/stock_valuation_layer.py b/account_move_line_repair_info/models/stock_valuation_layer.py new file mode 100644 index 000000000..94cc998af --- /dev/null +++ b/account_move_line_repair_info/models/stock_valuation_layer.py @@ -0,0 +1,22 @@ +# Copyright 2022 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class StockValuationLayer(models.Model): + + _inherit = "stock.valuation.layer" + + def _validate_accounting_entries(self): + res = super()._validate_accounting_entries() + for svl in self: + if svl.stock_move_id.repair_id: + current_move = svl.account_move_id + if current_move: + current_move.line_ids.write( + { + "repair_order_id": svl.stock_move_id.repair_id.id, + } + ) + return res diff --git a/account_move_line_repair_info/static/description/index.html b/account_move_line_repair_info/static/description/index.html index 388633f35..8070f80b8 100644 --- a/account_move_line_repair_info/static/description/index.html +++ b/account_move_line_repair_info/static/description/index.html @@ -367,9 +367,9 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:501799819b3b4d34a900a1035efbf8ba3a021300c180e1d9e4097cecdf9eabdf +!! source digest: sha256:44a807b48cf561e9c5eb22bd9e1308e78246ab34e9ca623cea3ae9d108f29e80 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/account-financial-tools Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/account-financial-tools Translate me on Weblate Try me on Runboat

This module will add the repair order to journal items.

Table of contents

@@ -397,7 +397,7 @@ ul.auto-toc {

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 to smash it by providing a detailed and welcomed -feedback.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -421,7 +421,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome

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.

-

This module is part of the OCA/account-financial-tools project on GitHub.

+

This module is part of the OCA/account-financial-tools project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/account_move_line_repair_info/tests/test_account_move_line_repair_info.py b/account_move_line_repair_info/tests/test_account_move_line_repair_info.py index a81a2ba39..8f27f2a70 100644 --- a/account_move_line_repair_info/tests/test_account_move_line_repair_info.py +++ b/account_move_line_repair_info/tests/test_account_move_line_repair_info.py @@ -27,7 +27,7 @@ class TestAccountMoveLineRepairInfo(TransactionCase): { "name": "Test stock valuation", "code": "tv", - "user_type_id": self.env["account.account.type"].search([], limit=1).id, + "account_type": "asset_cash", "reconcile": True, "company_id": self.env.ref("base.main_company").id, } @@ -36,9 +36,7 @@ class TestAccountMoveLineRepairInfo(TransactionCase): { "name": "Test Payable", "code": "tpayable", - "user_type_id": self.env["account.account.type"] - .search([("type", "=", "payable")], limit=1) - .id, + "account_type": "liability_payable", "reconcile": True, "company_id": self.env.ref("base.main_company").id, } @@ -47,9 +45,7 @@ class TestAccountMoveLineRepairInfo(TransactionCase): { "name": "Test Receivable", "code": "treceivable", - "user_type_id": self.env["account.account.type"] - .search([("type", "=", "receivable")], limit=1) - .id, + "account_type": "asset_receivable", "reconcile": True, "company_id": self.env.ref("base.main_company").id, } @@ -59,7 +55,7 @@ class TestAccountMoveLineRepairInfo(TransactionCase): { "name": "Test stock input", "code": "tsti", - "user_type_id": self.env["account.account.type"].search([], limit=1).id, + "account_type": "income", "reconcile": True, "company_id": self.env.ref("base.main_company").id, } @@ -68,7 +64,7 @@ class TestAccountMoveLineRepairInfo(TransactionCase): { "name": "Test stock output", "code": "tout", - "user_type_id": self.env["account.account.type"].search([], limit=1).id, + "account_type": "equity", "reconcile": True, "company_id": self.env.ref("base.main_company").id, } @@ -77,9 +73,7 @@ class TestAccountMoveLineRepairInfo(TransactionCase): { "name": "Test stock income", "code": "tincome", - "user_type_id": self.env["account.account.type"] - .search([("internal_group", "=", "income")], limit=1) - .id, + "account_type": "income", "reconcile": True, "company_id": self.env.ref("base.main_company").id, } @@ -88,9 +82,7 @@ class TestAccountMoveLineRepairInfo(TransactionCase): { "name": "Test stock outcome", "code": "texpense", - "user_type_id": self.env["account.account.type"] - .search([("internal_group", "=", "expense")], limit=1) - .id, + "account_type": "expense", "reconcile": True, "company_id": self.env.ref("base.main_company").id, } @@ -375,7 +367,7 @@ class TestAccountMoveLineRepairInfo(TransactionCase): "active_model": "repair.order", "active_ids": repairs.ids, } - res = make_invoice.with_context(context).make_invoices() + res = make_invoice.with_context(context=context).make_invoices() invoices = res.get("domain", []) and self.am_model.browse( res.get("domain", [])[0][2] )