diff --git a/account_asset_management_extension/README.rst b/account_asset_management_extension/README.rst new file mode 100644 index 000000000..efc3aefb3 --- /dev/null +++ b/account_asset_management_extension/README.rst @@ -0,0 +1,65 @@ +================================== +Account Asset Management Extension +================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:4efba3fd6254fdeeab7ce79dec3cf0773f88f49eb51a130c2e1f27ef00d3d9b7 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-NuoBiT%2Fodoo--addons-lightgray.png?logo=github + :target: https://github.com/NuoBiT/odoo-addons/tree/18.0/account_asset_management_extension + :alt: NuoBiT/odoo-addons + +|badge1| |badge2| |badge3| + +This module adds additional fields on assets. + +**Table of contents** + +.. contents:: + :local: + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* NuoBiT Solutions SL + +Contributors +------------ + +- `NuoBiT `__: + + - Kilian Niubo kniubo@nuobit.com + - Eric Antones eantones@nuobit.com + - Bijaya Kumal bkumal@nuobit.com + - Deniz Gallo dgallo@nuobit.com + +Maintainers +----------- + +This module is part of the `NuoBiT/odoo-addons `_ project on GitHub. + +You are welcome to contribute. diff --git a/account_asset_management_extension/__init__.py b/account_asset_management_extension/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/account_asset_management_extension/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_asset_management_extension/__manifest__.py b/account_asset_management_extension/__manifest__.py new file mode 100644 index 000000000..a65b00037 --- /dev/null +++ b/account_asset_management_extension/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright NuoBiT - Kilian Niubo +# Copyright 2025 NuoBiT Solutions - Deniz Gallo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +{ + "name": "Account Asset Management Extension", + "summary": "This module adds additional fields in assets", + "version": "18.0.1.0.0", + "category": "Accounting", + "author": "NuoBiT Solutions SL", + "website": "https://github.com/NuoBiT/odoo-addons", + "license": "AGPL-3", + "depends": [ + "account_asset_management", + ], + "data": [ + "views/account_asset.xml", + ], +} diff --git a/account_asset_management_extension/i18n/es.po b/account_asset_management_extension/i18n/es.po new file mode 100644 index 000000000..64cf1d589 --- /dev/null +++ b/account_asset_management_extension/i18n/es.po @@ -0,0 +1,97 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_asset_management_extension +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-09-29 12:35+0000\n" +"PO-Revision-Date: 2022-09-29 12:35+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_asset_management_extension +#: model:ir.model,name:account_asset_management_extension.model_account_asset +msgid "Asset" +msgstr "Activo" + +#. module: account_asset_management_extension +#: model:ir.model.fields,field_description:account_asset_management_extension.field_account_asset__currency_id +msgid "Currency" +msgstr "Divisa" + +#. module: account_asset_management_extension +#: model:ir.model.fields,field_description:account_asset_management_extension.field_account_asset__invoice_date +msgid "Invoice Date" +msgstr "Fecha de la factura" + +#. module: account_asset_management_extension +#: model:ir.model.fields,field_description:account_asset_management_extension.field_account_asset__invoice_ref +msgid "Invoice Reference" +msgstr "Referencia de la factura" + +#. module: account_asset_management_extension +#: model_terms:ir.ui.view,arch_db:account_asset_management_extension.account_asset_view_form +msgid "Other Information" +msgstr "Otra informacion" + +#. module: account_asset_management_extension +#: model:ir.model.fields,field_description:account_asset_management_extension.field_account_asset__tax_base_amount +msgid "Tax Base Amount" +msgstr "Importe de la base imponible" + +#. module: account_asset_management_extension +#: model:ir.model.fields,field_description:account_asset_management_extension.field_account_asset__invoice_move_line_id +msgid "Invoice Move Line" +msgstr "Línea de factura" + +#. module: account_asset_management_extension +#: model:ir.model.fields,field_description:account_asset_management_extension.field_account_asset__tax_ids +msgid "Taxes" +msgstr "Impuestos" + +#. module: account_asset_management_extension +#: model:ir.model.fields,field_description:account_asset_management_extension.field_account_asset__quantity +msgid "Quantity" +msgstr "Cantidad" + +#. module: account_asset_management_extension +#: code:addons/account_asset_management_extension/models/account_asset.py:0 +#, python-format +msgid "Quantity in asset can't be 0" +msgstr "La cantidad del activo no puede ser 0." + +#. module: account_asset_management_extension +#: code:addons/account_asset_management_extension/models/account_asset.py:0 +#, python-format +msgid "Invoice date must be the same as the one in the invoice: %s" +msgstr "La fecha de factura debe ser la misma que la establecida en la factura: %s" + +#. module: account_asset_management_extension +#: code:addons/account_asset_management_extension/models/account_asset.py:0 +#, python-format +msgid "Invoice ref must be the same as the one in the invoice: %s" +msgstr "La referencia de factura debe ser la misma que la establecida en la factura: %s" + +#. module: account_asset_management_extension +#: code:addons/account_asset_management_extension/models/account_asset.py:0 +#, python-format +msgid "Taxes must be the same as the ones in the invoice line: %s" +msgstr "Los impuestos deben ser los mismos que los establecidos en la línea de la factura: %s" + +#. module: account_asset_management_extension +#: code:addons/account_asset_management_extension/models/account_asset.py:0 +#, python-format +msgid "Tax base amount must be the same as the one in the invoice line: %s" +msgstr "El importe de la base imponible debe ser el mismo que el establecido en la línea de factura: %s" + +#. module: account_asset_management_extension +#: code:addons/account_asset_management_extension/models/account_asset.py:0 +#, python-format +msgid "Quantity must be the same as the one in the invoice line: %s" +msgstr "La cantidad debe ser la misma que la establecida en la línea de factura: %s" diff --git a/account_asset_management_extension/models/__init__.py b/account_asset_management_extension/models/__init__.py new file mode 100644 index 000000000..5e6c81c12 --- /dev/null +++ b/account_asset_management_extension/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_asset +from . import account_move diff --git a/account_asset_management_extension/models/account_asset.py b/account_asset_management_extension/models/account_asset.py new file mode 100644 index 000000000..226a9e2b2 --- /dev/null +++ b/account_asset_management_extension/models/account_asset.py @@ -0,0 +1,149 @@ +# Copyright NuoBiT Solutions - Kilian Niubo +# Copyright NuoBiT Solutions - Eric Antones +# Copyright 2025 NuoBiT Solutions - Bijaya Kumal +# Copyright 2025 NuoBiT Solutions - Deniz Gallo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +import json + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError +from odoo.tools import float_compare + + +class AccountAsset(models.Model): + _inherit = "account.asset" + + invoice_ref = fields.Char() + invoice_date = fields.Date() + quantity = fields.Float( + required=True, + ) + tax_base_amount = fields.Float( + compute="_compute_tax_base_amount", + readonly=False, + store=True, + ) + + @api.depends("purchase_value") + def _compute_tax_base_amount(self): + for rec in self: + rec.tax_base_amount = rec.purchase_value + + tax_base_amount_unit = fields.Float( + compute="_compute_tax_base_amount_unit", + ) + + @api.model + def _get_asset_unit_price(self, amount, quantity): + if not quantity: + amount = 0 + elif abs(quantity) > 1: + prec = self.env["decimal.precision"].precision_get( + "Product Unit of Measure" + ) + if not float_compare(int(quantity), quantity, precision_digits=prec): + amount /= quantity + return amount + + @api.depends("tax_base_amount", "quantity") + def _compute_tax_base_amount_unit(self): + for rec in self: + tax_base_amount = rec.tax_base_amount + if rec.quantity: + tax_base_amount = rec._get_asset_unit_price( + rec.tax_base_amount, rec.quantity + ) + rec.tax_base_amount_unit = tax_base_amount + + @api.constrains("quantity") + def _check_quantity_on_asset(self): + for rec in self: + if rec.quantity == 0: + raise ValidationError(_("Quantity in asset can't be 0")) + + @api.constrains("invoice_ref", "invoice_date", "quantity", "tax_base_amount") + def _check_invoice(self): + for rec in self: + if rec.invoice_move_line_id: + if rec.invoice_move_line_id.move_id.ref != rec.invoice_ref: + raise ValidationError( + _("Invoice ref must be the same as the one in the invoice: %s") + % rec.invoice_move_line_id.move_id.ref + ) + if rec.invoice_move_line_id.move_id.invoice_date != rec.invoice_date: + raise ValidationError( + _("Invoice date must be the same as the one in the invoice: %s") + % rec.invoice_move_line_id.move_id.invoice_date + ) + if rec.invoice_move_line_id.quantity != rec.quantity: + raise ValidationError( + _( + "Quantity must be the same" + " as the one in the invoice line: %s" + ) + % rec.invoice_move_line_id.quantity + ) + if rec.invoice_move_line_id.balance != rec.tax_base_amount: + raise ValidationError( + _( + "Tax base amount must be the same as the one in the " + "invoice line: %s" + ) + % rec.invoice_move_line_id.balance + ) + if rec.invoice_move_line_id.tax_ids != rec.tax_ids: + raise ValidationError( + _("Taxes must be the same as the ones in the invoice line: %s") + % rec.invoice_move_line_id.tax_ids.mapped("name") + ) + + # needed for bypassing the restriction on m2m fields + # on Form class. Remove it when supported + json_tax_ids = fields.Char( + store=False, + ) + + tax_ids = fields.Many2many( + comodel_name="account.tax", + compute="_compute_tax_ids", + store=True, + readonly=False, + ) + + @api.depends("json_tax_ids") + def _compute_tax_ids(self): + for rec in self: + if rec.json_tax_ids: + rec.tax_ids = json.loads(rec.json_tax_ids) + + invoice_move_line_id = fields.Many2one( + comodel_name="account.move.line", + compute="_compute_invoice_move_line_id", + store=True, + ) + + @api.depends( + "account_move_line_ids", + "account_move_line_ids.display_type", + "account_move_line_ids.move_id", + "account_move_line_ids.move_id.move_type", + ) + def _compute_invoice_move_line_id(self): + for rec in self: + iml = rec.account_move_line_ids.filtered( + lambda x: x.move_id.move_type != "entry" + and x.display_type in ("product", "line_section", "line_note") + ) + if iml: + if len(iml) > 1: + raise ValidationError( + _( + "This asset have more than one move line linked. " + "Please, review invoices: %s" + ) + % iml.mapped("move_id").mapped("name") + ) + rec.invoice_move_line_id = iml[0] + else: + rec.invoice_move_line_id = False diff --git a/account_asset_management_extension/models/account_move.py b/account_asset_management_extension/models/account_move.py new file mode 100644 index 000000000..e42769fa2 --- /dev/null +++ b/account_asset_management_extension/models/account_move.py @@ -0,0 +1,24 @@ +# Copyright NuoBiT Solutions - Kilian Niubo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + + +import json + +from odoo import models + + +class AccountMove(models.Model): + _inherit = "account.move" + + def _prepare_asset_vals(self, aml): + vals = super()._prepare_asset_vals(aml) + vals.update( + { + "invoice_ref": self.ref, + "invoice_date": self.invoice_date, + "quantity": aml.quantity, + "tax_base_amount": aml.balance, + "json_tax_ids": json.dumps(aml.tax_ids.ids), + } + ) + return vals diff --git a/account_asset_management_extension/pyproject.toml b/account_asset_management_extension/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/account_asset_management_extension/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/account_asset_management_extension/readme/CONTRIBUTORS.md b/account_asset_management_extension/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..5523253d9 --- /dev/null +++ b/account_asset_management_extension/readme/CONTRIBUTORS.md @@ -0,0 +1,6 @@ +- [NuoBiT](https://www.nuobit.com): + - Kilian Niubo + - Eric Antones + - Bijaya Kumal + - Deniz Gallo + diff --git a/account_asset_management_extension/readme/DESCRIPTION.md b/account_asset_management_extension/readme/DESCRIPTION.md new file mode 100644 index 000000000..b95b82a8c --- /dev/null +++ b/account_asset_management_extension/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module adds additional fields on assets. diff --git a/account_asset_management_extension/static/description/icon.png b/account_asset_management_extension/static/description/icon.png new file mode 100644 index 000000000..1cd641e79 Binary files /dev/null and b/account_asset_management_extension/static/description/icon.png differ diff --git a/account_asset_management_extension/static/description/index.html b/account_asset_management_extension/static/description/index.html new file mode 100644 index 000000000..287dec0ec --- /dev/null +++ b/account_asset_management_extension/static/description/index.html @@ -0,0 +1,422 @@ + + + + + +Account Asset Management Extension + + + +
+

Account Asset Management Extension

+ + +

Beta License: AGPL-3 NuoBiT/odoo-addons

+

This module adds additional fields on assets.

+

Table of contents

+ +
+

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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • NuoBiT Solutions SL
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is part of the NuoBiT/odoo-addons project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/account_asset_management_extension/views/account_asset.xml b/account_asset_management_extension/views/account_asset.xml new file mode 100644 index 000000000..799176e87 --- /dev/null +++ b/account_asset_management_extension/views/account_asset.xml @@ -0,0 +1,55 @@ + + + + + account.asset + + + + + + + + + + + + + + + + + + + + + + + + + + +