Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][IMP] maintenance_account: Create equipment description from move line name #386

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion maintenance_account/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Maintenance Account
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:67684d651aad4f717395cb7f97e2a9d365438bb7ae35f38e692b39cc05848999
!! source digest: sha256:5984a0b0e7a48a82c05223b890a4f95a079864896373f2281b10e7260ec1aad4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -72,6 +72,7 @@ Contributors

* Víctor Martínez
* Pedro M. Baeza
* Carolina Fernandez

Maintainers
~~~~~~~~~~~
Expand Down
10 changes: 9 additions & 1 deletion maintenance_account/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2022 Tecnativa - Víctor Martínez
# Copyright 2024 Tecnativa - Carolina Fernandez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models

Expand Down Expand Up @@ -113,13 +114,20 @@ def _set_equipment_category(self):
self.equipment_category_id = category.id

def _prepare_equipment_vals(self):
equipment_name = self.name
description = False
if "\n" in self.name:
lf_index = self.name.index("\n")
equipment_name = self.name[:lf_index]
description = self.name[lf_index + 1 :]
return {
"move_line_id": self.id,
"name": self.product_id.name,
"name": equipment_name,
"product_id": self.product_id.id,
"category_id": self.equipment_category_id.id,
"assign_date": self.move_id.date,
"effective_date": self.move_id.date,
"partner_id": self.move_id.partner_id.id,
"partner_ref": self.move_id.ref,
"note": description,
}
1 change: 1 addition & 0 deletions maintenance_account/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

* Víctor Martínez
* Pedro M. Baeza
* Carolina Fernandez
3 changes: 2 additions & 1 deletion maintenance_account/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Maintenance Account</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:67684d651aad4f717395cb7f97e2a9d365438bb7ae35f38e692b39cc05848999
!! source digest: sha256:5984a0b0e7a48a82c05223b890a4f95a079864896373f2281b10e7260ec1aad4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/maintenance/tree/15.0/maintenance_account"><img alt="OCA/maintenance" src="https://img.shields.io/badge/github-OCA%2Fmaintenance-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/maintenance-15-0/maintenance-15-0-maintenance_account"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/maintenance&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module automatically creates the equipment when validating the purchase invoices.</p>
Expand Down Expand Up @@ -417,6 +417,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Víctor Martínez</li>
<li>Pedro M. Baeza</li>
<li>Carolina Fernandez</li>
</ul>
</li>
</ul>
Expand Down
7 changes: 6 additions & 1 deletion maintenance_account/tests/test_maintenance_account.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Copyright 2022-2023 Tecnativa - Víctor Martínez
# Copyright 2024 Tecnativa - Carolina Fernandez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

from odoo import fields
from odoo.tests import Form, common, new_test_user
from odoo.tests.common import users
from odoo.tools import html2plaintext


class TestAccountMove(common.TransactionCase):
Expand Down Expand Up @@ -66,6 +68,7 @@ def _create_invoice(self, move_type="in_invoice"):
move_form.invoice_date = fields.Date.from_string("2000-01-01")
with move_form.invoice_line_ids.new() as line_form:
line_form.product_id = self.product_a
line_form.name = "Product A \nTest description product A"
line_form.quantity = 2
line_form.account_id = self.account_expense
with move_form.invoice_line_ids.new() as line_form:
Expand Down Expand Up @@ -100,7 +103,9 @@ def test_invoice_action_post_equipment_1(self):
self.assertEqual(len(line_a.equipment_ids), 2)
self.assertEqual(len(line_b.equipment_ids), 0)
equipment = fields.first(equipments)
self.assertEqual(equipment.name, self.product_a.name)
name_list = line_a.name.split("\n")
self.assertEqual(equipment.name, name_list[0])
self.assertEqual(html2plaintext(equipment.note), name_list[1])
self.assertEqual(equipment.product_id, self.product_a)
self.assertEqual(equipment.category_id.product_category_id, self.categ)
self.assertEqual(equipment.assign_date, invoice.date)
Expand Down
Loading