diff --git a/account_move_line_landed_cost_info/README.rst b/account_move_line_landed_cost_info/README.rst new file mode 100644 index 000000000..4638c7a09 --- /dev/null +++ b/account_move_line_landed_cost_info/README.rst @@ -0,0 +1,83 @@ +================================== +Account Move Line Landed Cost 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_landed_cost_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_landed_cost_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 landed cost info to journal items. + +The ultimate goal is to establish the landed cost adjustments as one of the key +fields to reconcile the Goods Delviered Not Invoiced accrual account. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +The adjustment line of the landed cost will be automatically copied to the journal +items when validating a landed cost. + +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 + +Contributors +~~~~~~~~~~~~ + +* Jordi Ballester Alomar +* Aaron Henriquez + +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_landed_cost_info/__init__.py b/account_move_line_landed_cost_info/__init__.py new file mode 100644 index 000000000..e66fb1c2e --- /dev/null +++ b/account_move_line_landed_cost_info/__init__.py @@ -0,0 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models +from .hooks import post_init_hook diff --git a/account_move_line_landed_cost_info/__manifest__.py b/account_move_line_landed_cost_info/__manifest__.py new file mode 100644 index 000000000..2f2024520 --- /dev/null +++ b/account_move_line_landed_cost_info/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2022 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Account Move Line Landed Cost Info", + "summary": "Introduces the landed cost adjustment lines to the journal items", + "version": "14.0.1.0.0", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/account-financial-tools", + "category": "Generic", + "depends": ["stock_landed_costs"], + "license": "AGPL-3", + "data": ["views/account_move_view.xml"], + "post_init_hook": "post_init_hook", + "installable": True, +} diff --git a/account_move_line_landed_cost_info/hooks.py b/account_move_line_landed_cost_info/hooks.py new file mode 100644 index 000000000..9ce9c18c2 --- /dev/null +++ b/account_move_line_landed_cost_info/hooks.py @@ -0,0 +1,80 @@ +# Copyright 2022 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import logging + +from odoo import SUPERUSER_ID, api + +_logger = logging.getLogger( + "Adding stock valuation adjustment line to the account move line" +) + + +def add_stock_valuation_adjustment_line(env): + """based on the account_move_line on the landed cost I search for the lines with + the same product. + """ + for val_adj_line in env["stock.valuation.adjustment.lines"].search([]): + landed_cost = val_adj_line.cost_id + am = landed_cost.account_move_id + if not am: + continue + if len(landed_cost.valuation_adjustment_lines) == 1: + # if only one adjustment all the journal items are for the same val_adj_line + _logger.info( + "Assigning %s for %s to %s" + % ( + am.name, + val_adj_line.product_id.display_name, + val_adj_line.cost_id.name, + ) + ) + matched_lines = am.line_ids.filtered(lambda l: not l.stock_landed_cost_id) + if matched_lines: + env.cr.execute( + """UPDATE account_move_line + SET (stock_valuation_adjustment_line_id, stock_landed_cost_id) = (%s,%s) + WHERE id in %s""", + ( + val_adj_line.id, + landed_cost.id, + tuple(am.line_ids.ids), + ), + ) + elif len(landed_cost.valuation_adjustment_lines): + # We could match by product, but, there may be several adjustment lines + # for the same product. And qty or the additional value added do not + # match in a normal case, because the quantities could already leave the + # company, so it is best to fill the stock landed cost info only + matched_lines = am.line_ids.filtered(lambda l: not l.stock_landed_cost_id) + _logger.info( + "Assigning %s to %s" + % ( + am.name, + val_adj_line.cost_id.name, + ) + ) + if matched_lines: + env.cr.execute( + """UPDATE account_move_line + SET stock_landed_cost_id = %s + WHERE id in %s""", + ( + landed_cost.id, + tuple(matched_lines.ids), + ), + ) + else: + _logger.info( + "Could not match account move line for %s and %s, product %s" + % ( + landed_cost.name, + am.name, + val_adj_line.product_id.display_name, + ) + ) + + +def post_init_hook(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + add_stock_valuation_adjustment_line(env) diff --git a/account_move_line_landed_cost_info/models/__init__.py b/account_move_line_landed_cost_info/models/__init__.py new file mode 100644 index 000000000..1ef6794a5 --- /dev/null +++ b/account_move_line_landed_cost_info/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_move +from . import stock_valuation_adjustment_lines diff --git a/account_move_line_landed_cost_info/models/account_move.py b/account_move_line_landed_cost_info/models/account_move.py new file mode 100644 index 000000000..094e1a5a4 --- /dev/null +++ b/account_move_line_landed_cost_info/models/account_move.py @@ -0,0 +1,21 @@ +# Copyright 2022 ForgeFlow S.L. +# 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" + + stock_valuation_adjustment_line_id = fields.Many2one( + comodel_name="stock.valuation.adjustment.lines", + string="Stock Valuation Adjustment Line", + store=True, + index=True, + ) + stock_landed_cost_id = fields.Many2one( + "stock.landed.cost", + related="stock_valuation_adjustment_line_id.cost_id", + store=True, + ) diff --git a/account_move_line_landed_cost_info/models/stock_valuation_adjustment_lines.py b/account_move_line_landed_cost_info/models/stock_valuation_adjustment_lines.py new file mode 100644 index 000000000..c3c62f11f --- /dev/null +++ b/account_move_line_landed_cost_info/models/stock_valuation_adjustment_lines.py @@ -0,0 +1,24 @@ +# Copyright 2022 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class AdjustmentLines(models.Model): + _inherit = "stock.valuation.adjustment.lines" + + def _create_account_move_line( + self, move, credit_account_id, debit_account_id, qty_out, already_out_account_id + ): + """ + Adds the adjustment line to the account move line. This method is called always + for a single line in self. + """ + res = super()._create_account_move_line( + move, credit_account_id, debit_account_id, qty_out, already_out_account_id + ) + for line in res: + if isinstance(line, list) and isinstance(line[2], dict): + line[2]["stock_valuation_adjustment_line_id"] = self.id + line[2]["stock_landed_cost_id"] = self.cost_id.id + return res diff --git a/account_move_line_landed_cost_info/readme/CONTRIBUTORS.rst b/account_move_line_landed_cost_info/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..3a08b15eb --- /dev/null +++ b/account_move_line_landed_cost_info/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Jordi Ballester Alomar +* Aaron Henriquez diff --git a/account_move_line_landed_cost_info/readme/DESCRIPTION.rst b/account_move_line_landed_cost_info/readme/DESCRIPTION.rst new file mode 100644 index 000000000..963d544db --- /dev/null +++ b/account_move_line_landed_cost_info/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This module will add the landed cost info to journal items. + +The ultimate goal is to establish the landed cost adjustments as one of the key +fields to reconcile the Goods Delviered Not Invoiced accrual account. diff --git a/account_move_line_landed_cost_info/readme/USAGE.rst b/account_move_line_landed_cost_info/readme/USAGE.rst new file mode 100644 index 000000000..7f663c9af --- /dev/null +++ b/account_move_line_landed_cost_info/readme/USAGE.rst @@ -0,0 +1,2 @@ +The adjustment line of the landed cost will be automatically copied to the journal +items when validating a landed cost. diff --git a/account_move_line_landed_cost_info/static/description/icon.png b/account_move_line_landed_cost_info/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_move_line_landed_cost_info/static/description/icon.png differ diff --git a/account_move_line_landed_cost_info/static/description/index.html b/account_move_line_landed_cost_info/static/description/index.html new file mode 100644 index 000000000..4b97fb67f --- /dev/null +++ b/account_move_line_landed_cost_info/static/description/index.html @@ -0,0 +1,428 @@ + + + + + + +Account Move Line Landed Cost Info + + + +
+

Account Move Line Landed Cost Info

+ + +

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

+

This module will add the landed cost info to journal items.

+

The ultimate goal is to establish the landed cost adjustments as one of the key +fields to reconcile the Goods Delviered Not Invoiced accrual account.

+

Table of contents

+ +
+

Usage

+

The adjustment line of the landed cost will be automatically copied to the journal +items when validating a landed cost.

+
+
+

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
  • +
+
+
+

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_landed_cost_info/views/account_move_view.xml b/account_move_line_landed_cost_info/views/account_move_view.xml new file mode 100644 index 000000000..573b88d7b --- /dev/null +++ b/account_move_line_landed_cost_info/views/account_move_view.xml @@ -0,0 +1,56 @@ + + + + account.move.line.form + account.move.line + + + + + + + + + account.move.line.tree + account.move.line + + + + + + + + + + Journal Items + account.move.line + + + + + + + + + + + + account.move.form + account.move + + + + + + + + + diff --git a/setup/account_move_line_landed_cost_info/odoo/addons/account_move_line_landed_cost_info b/setup/account_move_line_landed_cost_info/odoo/addons/account_move_line_landed_cost_info new file mode 120000 index 000000000..249e8aec3 --- /dev/null +++ b/setup/account_move_line_landed_cost_info/odoo/addons/account_move_line_landed_cost_info @@ -0,0 +1 @@ +../../../../account_move_line_landed_cost_info \ No newline at end of file diff --git a/setup/account_move_line_landed_cost_info/setup.py b/setup/account_move_line_landed_cost_info/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/account_move_line_landed_cost_info/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)