From f1381f382018494a2f82015da2906c110663844c Mon Sep 17 00:00:00 2001 From: Christopher Ormaza Date: Tue, 29 Mar 2022 14:55:26 -0500 Subject: [PATCH] [14.0][ADD] account_move_line_repair_info --- account_move_line_repair_info/README.rst | 81 ++++ account_move_line_repair_info/__init__.py | 2 + account_move_line_repair_info/__manifest__.py | 21 + account_move_line_repair_info/hooks.py | 71 +++ .../models/__init__.py | 3 + .../models/account_move.py | 99 ++++ .../models/repair_order.py | 16 + .../models/stock_move.py | 39 ++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 1 + .../readme/USAGE.rst | 4 + .../security/account_security.xml | 8 + .../static/description/index.html | 428 ++++++++++++++++++ .../tests/__init__.py | 1 + .../test_account_move_line_repair_info.py | 398 ++++++++++++++++ .../views/account_move_view.xml | 52 +++ 16 files changed, 1225 insertions(+) create mode 100644 account_move_line_repair_info/README.rst create mode 100644 account_move_line_repair_info/__init__.py create mode 100644 account_move_line_repair_info/__manifest__.py create mode 100644 account_move_line_repair_info/hooks.py create mode 100644 account_move_line_repair_info/models/__init__.py create mode 100644 account_move_line_repair_info/models/account_move.py create mode 100644 account_move_line_repair_info/models/repair_order.py create mode 100644 account_move_line_repair_info/models/stock_move.py create mode 100644 account_move_line_repair_info/readme/CONTRIBUTORS.rst create mode 100644 account_move_line_repair_info/readme/DESCRIPTION.rst create mode 100644 account_move_line_repair_info/readme/USAGE.rst create mode 100644 account_move_line_repair_info/security/account_security.xml create mode 100644 account_move_line_repair_info/static/description/index.html create mode 100644 account_move_line_repair_info/tests/__init__.py create mode 100644 account_move_line_repair_info/tests/test_account_move_line_repair_info.py create mode 100644 account_move_line_repair_info/views/account_move_view.xml diff --git a/account_move_line_repair_info/README.rst b/account_move_line_repair_info/README.rst new file mode 100644 index 000000000..9d39d6371 --- /dev/null +++ b/account_move_line_repair_info/README.rst @@ -0,0 +1,81 @@ +============================= +Account Move Line Repair Info +============================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :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 + :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 + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/92/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module will add the repair order to journal items. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +The repair order will be automatically copied to the journal items. + +* When Invoice(s) is made from repair order, field repair_order_id +* The journal entries created by the consumption of materials and the repaired product, are associated with the repair order + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow S.L. + +Contributors +~~~~~~~~~~~~ + +* Christopher Ormaza + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_move_line_repair_info/__init__.py b/account_move_line_repair_info/__init__.py new file mode 100644 index 000000000..cc6b6354a --- /dev/null +++ b/account_move_line_repair_info/__init__.py @@ -0,0 +1,2 @@ +from . import models +from .hooks import post_init_hook diff --git a/account_move_line_repair_info/__manifest__.py b/account_move_line_repair_info/__manifest__.py new file mode 100644 index 000000000..bfcfca8e3 --- /dev/null +++ b/account_move_line_repair_info/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2022 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Account Move Line Repair Info", + "summary": "Introduces the repair order to the journal items", + "version": "14.0.1.0.0", + "author": "ForgeFlow S.L., " "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/account-financial-tools", + "category": "Generic", + "depends": [ + "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"], + "installable": True, + "post_init_hook": "post_init_hook", +} diff --git a/account_move_line_repair_info/hooks.py b/account_move_line_repair_info/hooks.py new file mode 100644 index 000000000..653b9c141 --- /dev/null +++ b/account_move_line_repair_info/hooks.py @@ -0,0 +1,71 @@ +# Copyright 2022 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +def post_init_hook(cr, registry): + # Material consumed on repair + cr.execute( + """ + update account_move_line as aml set repair_order_id = q.order_id + from ( + select aml.id, ro.id as order_id + from account_move_line as aml + left join account_move as am on am.id = aml.move_id + left join stock_valuation_layer svl on svl.account_move_id = am.id + left join stock_move as sm on sm.id = svl.stock_move_id + left join repair_line as rl on rl.move_id = sm.id + left join repair_order as ro on rl.repair_id = ro.id + where ro.id is not null + ) as q + where q.id = aml.id + """ + ) + + # Product Repaired + cr.execute( + """ + update account_move_line as aml set repair_order_id = q.order_id + from ( + select aml.id, ro.id as order_id + from account_move_line as aml + left join account_move as am on am.id = aml.move_id + left join stock_valuation_layer svl on svl.account_move_id = am.id + left join stock_move as sm on sm.id = svl.stock_move_id + left join repair_order as ro on sm.id = ro.move_id + where ro.id is not null + ) as q + where q.id = aml.id + """ + ) + + # Invoice Lines for Products Consumed + cr.execute( + """ + update account_move_line as aml set repair_order_id = q.order_id + from ( + select aml.id, ro.id as order_id + from account_move_line as aml + left join account_move as am on am.id = aml.move_id + left join repair_line as rl on aml.id = rl.invoice_line_id + left join repair_order as ro on rl.repair_id = ro.id + where ro.id is not null + ) as q + where q.id = aml.id + """ + ) + + # Invoice Lines for Fees + cr.execute( + """ + update account_move_line as aml set repair_order_id = q.order_id + from ( + select aml.id, ro.id as order_id + from account_move_line as aml + left join account_move as am on am.id = aml.move_id + left join repair_fee as rf on aml.id = rf.invoice_line_id + left join repair_order as ro on rf.repair_id = ro.id + where ro.id is not null + ) as q + where q.id = aml.id + """ + ) diff --git a/account_move_line_repair_info/models/__init__.py b/account_move_line_repair_info/models/__init__.py new file mode 100644 index 000000000..16528a5e2 --- /dev/null +++ b/account_move_line_repair_info/models/__init__.py @@ -0,0 +1,3 @@ +from . import account_move +from . import repair_order +from . import stock_move diff --git a/account_move_line_repair_info/models/account_move.py b/account_move_line_repair_info/models/account_move.py new file mode 100644 index 000000000..facbf1819 --- /dev/null +++ b/account_move_line_repair_info/models/account_move.py @@ -0,0 +1,99 @@ +# Copyright 2022 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +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, + } + ) + return res + + @api.model_create_multi + def create(self, values): + rline_model = self.env["repair.line"] + fline_model = self.env["repair.fee"] + rorder_model = self.env["repair.order"] + for val in values: + for invoice_line_ids in val.get("invoice_line_ids", []): + line_val = invoice_line_ids[2] + if line_val.get("repair_line_ids", []): + repair_line_ids = [ + r[1] for r in line_val.get("repair_line_ids", []) + ] + rline = rline_model.browse(repair_line_ids) + rorder = rline.mapped("repair_id") + if len(rorder) == 1: + line_val.update( + { + "repair_order_id": rline.mapped("repair_id").id, + } + ) + if line_val.get("repair_fee_ids", False): + repair_fee_ids = [r[1] for r in line_val.get("repair_fee_ids", [])] + fline = fline_model.browse(repair_fee_ids) + rorder = fline.mapped("repair_id") + if len(rorder) == 1: + line_val.update( + { + "repair_order_id": fline.mapped("repair_id").id, + } + ) + if line_val.get("repair_ids", False): + repair_ids = [r[1] for r in line_val.get("repair_ids", [])] + rorder = rorder_model.browse(repair_ids) + if len(rorder) == 1: + line_val.update( + { + "repair_order_id": rorder.id, + } + ) + return super(AccountMove, self).create(values) + + +class AccountMoveLine(models.Model): + + _inherit = "account.move.line" + + repair_order_id = fields.Many2one( + comodel_name="repair.order", + string="Repair Order", + ondelete="set null", + index=True, + copy=False, + ) diff --git a/account_move_line_repair_info/models/repair_order.py b/account_move_line_repair_info/models/repair_order.py new file mode 100644 index 000000000..fb7c743d7 --- /dev/null +++ b/account_move_line_repair_info/models/repair_order.py @@ -0,0 +1,16 @@ +# Copyright 2022 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class RepairOrder(models.Model): + + _inherit = "repair.order" + + account_move_line_ids = fields.One2many( + comodel_name="account.move.line", + inverse_name="repair_order_id", + string="Journal Entries", + required=False, + ) diff --git a/account_move_line_repair_info/models/stock_move.py b/account_move_line_repair_info/models/stock_move.py new file mode 100644 index 000000000..2812848a1 --- /dev/null +++ b/account_move_line_repair_info/models/stock_move.py @@ -0,0 +1,39 @@ +# 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/readme/CONTRIBUTORS.rst b/account_move_line_repair_info/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..b647a292e --- /dev/null +++ b/account_move_line_repair_info/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Christopher Ormaza diff --git a/account_move_line_repair_info/readme/DESCRIPTION.rst b/account_move_line_repair_info/readme/DESCRIPTION.rst new file mode 100644 index 000000000..2416227b4 --- /dev/null +++ b/account_move_line_repair_info/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module will add the repair order to journal items. diff --git a/account_move_line_repair_info/readme/USAGE.rst b/account_move_line_repair_info/readme/USAGE.rst new file mode 100644 index 000000000..e33eb60fc --- /dev/null +++ b/account_move_line_repair_info/readme/USAGE.rst @@ -0,0 +1,4 @@ +The repair order will be automatically copied to the journal items. + +* When Invoice(s) is made from repair order, field repair_order_id +* The journal entries created by the consumption of materials and the repaired product, are associated with the repair order diff --git a/account_move_line_repair_info/security/account_security.xml b/account_move_line_repair_info/security/account_security.xml new file mode 100644 index 000000000..56158e9c7 --- /dev/null +++ b/account_move_line_repair_info/security/account_security.xml @@ -0,0 +1,8 @@ + + + + Repair Order info in Journal Items + + + + diff --git a/account_move_line_repair_info/static/description/index.html b/account_move_line_repair_info/static/description/index.html new file mode 100644 index 000000000..3c55f3b1b --- /dev/null +++ b/account_move_line_repair_info/static/description/index.html @@ -0,0 +1,428 @@ + + + + + + +Account Move Line Repair Info + + + +
+

Account Move Line Repair Info

+ + +

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

+

This module will add the repair order to journal items.

+

Table of contents

+ +
+

Usage

+

The repair order will be automatically copied to the journal items.

+
    +
  • When Invoice(s) is made from repair order, field repair_order_id
  • +
  • The journal entries created by the consumption of materials and the repaired product, are associated with the repair order
  • +
+
+
+

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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow S.L.
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

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/__init__.py b/account_move_line_repair_info/tests/__init__.py new file mode 100644 index 000000000..ceb307b61 --- /dev/null +++ b/account_move_line_repair_info/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_move_line_repair_info 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 new file mode 100644 index 000000000..a81a2ba39 --- /dev/null +++ b/account_move_line_repair_info/tests/test_account_move_line_repair_info.py @@ -0,0 +1,398 @@ +# Copyright 2022 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +# flake8: noqa: B950 + +from odoo import fields +from odoo.tests.common import TransactionCase + + +class TestAccountMoveLineRepairInfo(TransactionCase): + def setUp(self): + super().setUp() + self.aml_model = self.env["account.move.line"] + self.am_model = self.env["account.move"] + self.chart_template = self.env["account.chart.template"].create( + { + "name": "Test chart", + "currency_id": self.env.ref("base.EUR").id, + "code_digits": 6, + "cash_account_code_prefix": "570", + "bank_account_code_prefix": "572", + "transfer_account_code_prefix": "100000", + "use_anglo_saxon": True, + } + ) + self.chart_template.try_loading(company=self.env.user.company_id) + self.valuation_account = self.env["account.account"].create( + { + "name": "Test stock valuation", + "code": "tv", + "user_type_id": self.env["account.account.type"].search([], limit=1).id, + "reconcile": True, + "company_id": self.env.ref("base.main_company").id, + } + ) + self.payable_account = self.env["account.account"].create( + { + "name": "Test Payable", + "code": "tpayable", + "user_type_id": self.env["account.account.type"] + .search([("type", "=", "payable")], limit=1) + .id, + "reconcile": True, + "company_id": self.env.ref("base.main_company").id, + } + ) + self.receivable_account = self.env["account.account"].create( + { + "name": "Test Receivable", + "code": "treceivable", + "user_type_id": self.env["account.account.type"] + .search([("type", "=", "receivable")], limit=1) + .id, + "reconcile": True, + "company_id": self.env.ref("base.main_company").id, + } + ) + + self.stock_input_account = self.env["account.account"].create( + { + "name": "Test stock input", + "code": "tsti", + "user_type_id": self.env["account.account.type"].search([], limit=1).id, + "reconcile": True, + "company_id": self.env.ref("base.main_company").id, + } + ) + self.stock_output_account = self.env["account.account"].create( + { + "name": "Test stock output", + "code": "tout", + "user_type_id": self.env["account.account.type"].search([], limit=1).id, + "reconcile": True, + "company_id": self.env.ref("base.main_company").id, + } + ) + self.stock_income_account = self.env["account.account"].create( + { + "name": "Test stock income", + "code": "tincome", + "user_type_id": self.env["account.account.type"] + .search([("internal_group", "=", "income")], limit=1) + .id, + "reconcile": True, + "company_id": self.env.ref("base.main_company").id, + } + ) + self.stock_expense_account = self.env["account.account"].create( + { + "name": "Test stock outcome", + "code": "texpense", + "user_type_id": self.env["account.account.type"] + .search([("internal_group", "=", "expense")], limit=1) + .id, + "reconcile": True, + "company_id": self.env.ref("base.main_company").id, + } + ) + self.stock_journal = self.env["account.journal"].create( + {"name": "Stock Journal", "code": "STJTEST", "type": "general"} + ) + self.categ_real = self.env["product.category"].create( + { + "name": "REAL", + "property_cost_method": "fifo", + "property_valuation": "real_time", + "property_stock_valuation_account_id": self.valuation_account.id, + "property_stock_account_input_categ_id": self.stock_input_account.id, + "property_stock_account_output_categ_id": self.stock_output_account.id, + "property_account_expense_categ_id": self.stock_expense_account.id, + "property_account_income_categ_id": self.stock_income_account.id, + "property_stock_journal": self.stock_journal.id, + } + ) + self.res_partner_1 = self.env["res.partner"].create( + { + "name": "Wood Corner", + "property_account_payable_id": self.payable_account.id, + "property_account_receivable_id": self.receivable_account.id, + } + ) + self.res_partner_address_1 = self.env["res.partner"].create( + {"name": "Willie Burke", "parent_id": self.res_partner_1.id} + ) + self.res_partner_12 = self.env["res.partner"].create( + { + "name": "Partner 12", + "property_account_payable_id": self.payable_account.id, + "property_account_receivable_id": self.receivable_account.id, + } + ) + + # Products + self.product_product_3 = self.env["product.product"].create( + { + "name": "Desk Combination", + "categ_id": self.categ_real.id, + "standard_price": 1.0, + "type": "product", + } + ) + self.product_product_11 = self.env["product.product"].create( + { + "name": "Conference Chair", + "categ_id": self.categ_real.id, + "standard_price": 1.0, + "type": "product", + } + ) + self.product_product_5 = self.env["product.product"].create( + { + "name": "Product 5", + "categ_id": self.categ_real.id, + "standard_price": 1.0, + "type": "product", + } + ) + self.product_product_6 = self.env["product.product"].create( + { + "name": "Large Cabinet", + "categ_id": self.categ_real.id, + "standard_price": 1.0, + "type": "product", + } + ) + self.product_product_12 = self.env["product.product"].create( + { + "name": "Office Chair Black", + "categ_id": self.categ_real.id, + "standard_price": 1.0, + "type": "product", + } + ) + self.product_product_13 = self.env["product.product"].create( + { + "name": "Corner Desk Left Sit", + "categ_id": self.categ_real.id, + "standard_price": 1.0, + "type": "product", + } + ) + self.product_product_2 = self.env["product.product"].create( + { + "name": "Virtual Home Staging", + "categ_id": self.categ_real.id, + "standard_price": 1.0, + "type": "product", + } + ) + self.product_service_order_repair = self.env["product.product"].create( + { + "name": "Repair Services", + "type": "service", + "categ_id": self.categ_real.id, + } + ) + + # Location + self.stock_warehouse = self.env["stock.warehouse"].search( + [("company_id", "=", self.env.company.id)], limit=1 + ) + self.stock_location_14 = self.env["stock.location"].create( + { + "name": "Shelf 2", + "location_id": self.stock_warehouse.lot_stock_id.id, + } + ) + + # Repair Orders + self.repair1 = self.env["repair.order"].create( + { + "address_id": self.res_partner_address_1.id, + "guarantee_limit": fields.Date.today(), + "invoice_method": "none", + "user_id": False, + "product_id": self.product_product_3.id, + "product_uom": self.env.ref("uom.product_uom_unit").id, + "partner_invoice_id": self.res_partner_address_1.id, + "location_id": self.stock_warehouse.lot_stock_id.id, + "operations": [ + ( + 0, + 0, + { + "location_dest_id": self.product_product_11.property_stock_production.id, + "location_id": self.stock_warehouse.lot_stock_id.id, + "name": self.product_product_11.get_product_multiline_description_sale(), + "product_id": self.product_product_11.id, + "product_uom": self.env.ref("uom.product_uom_unit").id, + "product_uom_qty": 1.0, + "price_unit": 50.0, + "state": "draft", + "type": "add", + "company_id": self.env.company.id, + }, + ) + ], + "fees_lines": [ + ( + 0, + 0, + { + "name": self.product_service_order_repair.get_product_multiline_description_sale(), + "product_id": self.product_service_order_repair.id, + "product_uom_qty": 1.0, + "product_uom": self.env.ref("uom.product_uom_unit").id, + "price_unit": 50.0, + "company_id": self.env.company.id, + }, + ) + ], + "partner_id": self.res_partner_12.id, + } + ) + + self.repair0 = self.env["repair.order"].create( + { + "product_id": self.product_product_5.id, + "product_uom": self.env.ref("uom.product_uom_unit").id, + "address_id": self.res_partner_address_1.id, + "guarantee_limit": fields.Date.today(), + "invoice_method": "after_repair", + "user_id": False, + "partner_invoice_id": self.res_partner_address_1.id, + "location_id": self.stock_warehouse.lot_stock_id.id, + "operations": [ + ( + 0, + 0, + { + "location_dest_id": self.product_product_12.property_stock_production.id, + "location_id": self.stock_warehouse.lot_stock_id.id, + "name": self.product_product_12.get_product_multiline_description_sale(), + "price_unit": 50.0, + "product_id": self.product_product_12.id, + "product_uom": self.env.ref("uom.product_uom_unit").id, + "product_uom_qty": 1.0, + "state": "draft", + "type": "add", + "company_id": self.env.company.id, + }, + ) + ], + "fees_lines": [ + ( + 0, + 0, + { + "name": self.product_service_order_repair.get_product_multiline_description_sale(), + "product_id": self.product_service_order_repair.id, + "product_uom_qty": 1.0, + "product_uom": self.env.ref("uom.product_uom_unit").id, + "price_unit": 50.0, + "company_id": self.env.company.id, + }, + ) + ], + "partner_id": self.res_partner_12.id, + } + ) + + self.repair2 = self.env["repair.order"].create( + { + "product_id": self.product_product_6.id, + "product_uom": self.env.ref("uom.product_uom_unit").id, + "address_id": self.res_partner_address_1.id, + "guarantee_limit": fields.Date.today(), + "invoice_method": "b4repair", + "user_id": False, + "partner_invoice_id": self.res_partner_address_1.id, + "location_id": self.stock_location_14.id, + "operations": [ + ( + 0, + 0, + { + "location_dest_id": self.product_product_13.property_stock_production.id, + "location_id": self.stock_warehouse.lot_stock_id.id, + "name": self.product_product_13.get_product_multiline_description_sale(), + "price_unit": 50.0, + "product_id": self.product_product_13.id, + "product_uom": self.env.ref("uom.product_uom_unit").id, + "product_uom_qty": 1.0, + "state": "draft", + "type": "add", + "company_id": self.env.company.id, + }, + ) + ], + "fees_lines": [ + ( + 0, + 0, + { + "name": self.product_service_order_repair.get_product_multiline_description_sale(), + "product_id": self.product_service_order_repair.id, + "product_uom_qty": 1.0, + "product_uom": self.env.ref("uom.product_uom_unit").id, + "price_unit": 50.0, + "company_id": self.env.company.id, + }, + ) + ], + "partner_id": self.res_partner_12.id, + } + ) + + self.env.user.groups_id |= self.env.ref("stock.group_stock_user") + + def test_move_line_repair_info(self): + self.product_product_3.write({"categ_id": self.categ_real.id}) + self.product_product_11.write({"categ_id": self.categ_real.id}) + self.product_product_5.write({"categ_id": self.categ_real.id}) + self.product_product_6.write({"categ_id": self.categ_real.id}) + self.product_product_12.write({"categ_id": self.categ_real.id}) + self.product_product_13.write({"categ_id": self.categ_real.id}) + self.product_product_2.write({"categ_id": self.categ_real.id}) + repairs = self.repair0 + self.repair1 + self.repair2 + for repair in repairs: + repair.action_repair_confirm() + if repair.state != "2binvoiced": + repair.action_repair_start() + repair.action_repair_end() + for operation in repairs.filtered( + lambda x: x.state == "done" and x.move_id + ).mapped("operations"): + aml = self.aml_model.search( + [("move_id.stock_move_id", "=", operation.move_id.id)] + ) + if aml: + self.assertEqual( + aml.mapped("repair_order_id").ids, operation.repair_id.ids + ) + make_invoice = self.env["repair.order.make_invoice"].create({"group": True}) + context = { + "active_model": "repair.order", + "active_ids": repairs.ids, + } + res = make_invoice.with_context(context).make_invoices() + invoices = res.get("domain", []) and self.am_model.browse( + res.get("domain", [])[0][2] + ) + for invoice in invoices: + if invoice.state == "draft": + invoice.action_post() + for fee in repairs.mapped("fees_lines"): + invoice_lines = fee.repair_id.invoice_id.invoice_line_ids.filtered( + lambda x: fee.id in x.repair_fee_ids.ids + ) + if invoice_lines: + self.assertEqual(fee.repair_id.id, invoice_lines.repair_order_id.id) + for operation in repairs.mapped("operations"): + invoice_lines = operation.repair_id.invoice_id.invoice_line_ids.filtered( + lambda x: operation.id in x.repair_line_ids.ids + ) + if invoice_lines: + self.assertEqual( + operation.repair_id.id, invoice_lines.repair_order_id.id + ) diff --git a/account_move_line_repair_info/views/account_move_view.xml b/account_move_line_repair_info/views/account_move_view.xml new file mode 100644 index 000000000..af6cca51c --- /dev/null +++ b/account_move_line_repair_info/views/account_move_view.xml @@ -0,0 +1,52 @@ + + + + account.move.line.form + account.move.line + + + + + + + + + account.move.line.tree + account.move.line + + + + + + + + + Journal Items + account.move.line + + + + + + + + + + +