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

[16.0][MIG] account_move_line_rma_order_line: Migration to 16.0 #453

Merged
merged 15 commits into from
May 9, 2024
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
66 changes: 66 additions & 0 deletions account_move_line_rma_order_line/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
.. image:: https://img.shields.io/badge/license-AGPLv3-blue.svg
:target: https://www.gnu.org/licenses/agpl.html
:alt: License: AGPL-3

==========================
Account Move Line RMA Line
==========================

This module will add the RMA order line to journal items.

The ultimate goal is to establish the RMA order line as one of the key
fields to reconcile the Goods Received Not Invoiced accrual account.


Usage
=====

The RMA order line will be automatically copied to the journal items.

* When a supplier invoice is created referencing RMA orders, the
RMA order line will be copied to the corresponding journal item.

* When a stock move is validated and generates a journal entry, the RMA
order line is copied to the account move line.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/92/9.0

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/Eficent/stock_rma/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.


Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Jordi Ballester Alomar <[email protected]>
* Aarón Henríquez Quintana <[email protected]>

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

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.

To contribute to this module, please visit https://odoo-community.org.
42 changes: 42 additions & 0 deletions account_move_line_rma_order_line/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from . import models

import logging
from odoo import api, SUPERUSER_ID

_logger = logging.getLogger(__name__)


def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
aml_model = env["account.move.line"]
sm_model = env["stock.move"]
svl_model = env["stock.valuation.layer"]
aml_moves = aml_model.search([("rma_line_id", "!=", False)])
sm_moves = sm_model.search([("rma_line_id", "!=", False)])
for account_move in aml_moves.mapped("move_id"):
for aml_w_rma in account_move.line_ids.filtered(
lambda x: x.product_id
and x.account_id.id
!= x.product_id.categ_id.property_stock_valuation_account_id.id
and x.rma_line_id
):
move_lines_without_rma = account_move.line_ids.filtered(
lambda x: x.product_id.id == aml_w_rma.product_id.id
and not x.rma_line_id
and aml_w_rma.name in x.name
)
if move_lines_without_rma:
move_lines_without_rma.write(
{
"rma_line_id": aml_w_rma.rma_line_id.id,
}
)
for move in sm_moves:
current_layers = svl_model.search([("stock_move_id", "=", move.id)])
if current_layers:
for aml in current_layers.mapped("account_move_id.line_ids").filtered(
lambda x: x.account_id.id
!= move.product_id.categ_id.property_stock_valuation_account_id.id
and not x.rma_line_id
):
aml.rma_line_id = move.rma_line_id.id
19 changes: 19 additions & 0 deletions account_move_line_rma_order_line/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# © 2017-2022 ForgeFlow S.L. (www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

{
"name": "Account Move Line Rma Order Line",
"summary": "Introduces the rma order line to the journal items",
"version": "16.0.1.1.0",
"author": "ForgeFlow, " "Odoo Community Association (OCA)",
"website": "https://github.com/ForgeFlow/stock-rma",
"category": "Generic",
"depends": ["stock_account", "rma_account"],
"license": "AGPL-3",
"data": [],
"installable": True,
"maintainers": ["ChisOForgeFlow"],
"development_status": "Beta",
"post_init_hook": "post_init_hook",
"auto_install": True,
}
2 changes: 2 additions & 0 deletions account_move_line_rma_order_line/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import stock_move
from . import account_move
33 changes: 33 additions & 0 deletions account_move_line_rma_order_line/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# © 2017-2022 ForgeFlow S.L. (www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import models


class AccountMove(models.Model):

_inherit = "account.move"

def _stock_account_prepare_anglo_saxon_out_lines_vals(self):
product_model = self.env["product.product"]
res = super()._stock_account_prepare_anglo_saxon_out_lines_vals()
for line in res:
if line.get("product_id", False):
product = product_model.browse(line.get("product_id", False))
if (
line.get("account_id")
!= product.categ_id.property_stock_valuation_account_id.id
):
current_move = self.browse(line.get("move_id", False))
current_rma = current_move.invoice_line_ids.filtered(
lambda x: x.rma_line_id and x.product_id.id == product.id
).mapped("rma_line_id")
if len(current_rma) == 1:
line.update({"rma_line_id": current_rma.id})
elif len(current_rma) > 1:
find_with_label_rma = current_rma.filtered(
lambda x: x.name == line.get("name")
)
if len(find_with_label_rma) == 1:
line.update({"rma_line_id": find_with_label_rma.id})
return res
23 changes: 23 additions & 0 deletions account_move_line_rma_order_line/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# © 2017-2022 ForgeFlow S.L. (www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, models


class StockMove(models.Model):
_inherit = "stock.move"

@api.model
def _prepare_account_move_line(
self, qty, cost, credit_account_id, debit_account_id, svl_id, description
):
res = super(StockMove, self)._prepare_account_move_line(
qty, cost, credit_account_id, debit_account_id, svl_id, description
)
for line in res:
if (
line[2]["account_id"]
!= self.product_id.categ_id.property_stock_valuation_account_id.id
):
line[2]["rma_line_id"] = self.rma_line_id.id
return res
1 change: 1 addition & 0 deletions account_move_line_rma_order_line/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Christopher Ormaza <[email protected]>
4 changes: 4 additions & 0 deletions account_move_line_rma_order_line/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This module will add the RMA order line to journal items.

The ultimate goal is to establish the RMA order line as one of the key
fields to reconcile the Goods Received Not Invoiced accrual account.
7 changes: 7 additions & 0 deletions account_move_line_rma_order_line/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
The RMA order line will be automatically copied to the journal items.

* When a supplier invoice is created referencing RMA orders, the
RMA order line will be copied to the corresponding journal item.

* When a stock move is validated and generates a journal entry, the RMA
order line is copied to the account move line.
1 change: 1 addition & 0 deletions account_move_line_rma_order_line/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_account_move_line_rma_order_line
Loading
Loading