[IMP] rma: Refactor all rma modules in order to consider using the correct price unit in moves

Otherwise the inventory accounting will be completely wrong.
This commit is contained in:
Jordi Ballester
2022-03-02 11:35:08 +01:00
committed by JasminSForgeFlow
parent 23353f3c77
commit e76900463d
15 changed files with 75 additions and 25 deletions

View File

@@ -1,5 +1,2 @@
# © 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from . import models
from . import wizards

View File

@@ -1,13 +1,12 @@
# © 2017 Eficent Business and IT Consulting Services S.L.
# Copyright 2017-2022 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
{
"name": "RMA Purchase",
"version": "15.0.1.0.0",
"category": "RMA",
"summary": "RMA from PO",
"license": "LGPL-3",
"author": "Eficent, Odoo Community Association (OCA)",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/ForgeFlow/stock-rma",
"depends": ["rma_account", "purchase"],
"data": [
@@ -19,4 +18,5 @@
"wizards/rma_add_purchase.xml",
],
"installable": True,
"auto_install": True,
}

View File

@@ -1,7 +1,6 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from . import rma_order
from . import rma_order_line
from . import purchase_order
from . import purchase_order_line
from . import rma_operation
from . import procurement

View File

@@ -0,0 +1,61 @@
# Copyright 2017-2022 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo import fields, models
class StockRule(models.Model):
_inherit = "stock.rule"
def _get_stock_move_values(
self,
product_id,
product_qty,
product_uom,
location_id,
name,
origin,
company_id,
values,
):
res = super(StockRule, self)._get_stock_move_values(
product_id,
product_qty,
product_uom,
location_id,
name,
origin,
company_id,
values,
)
if "rma_line_id" in values:
line = values.get("rma_line_id")
if line.reference_move_id:
return res
if line.purchase_order_line_id:
moves = line.purchase_order_line_id.move_ids
if moves:
# TODO: Should we be smart in the choice of the move?
layers = moves.mapped("stock_valuation_layer_ids")
cost = layers[-1].unit_cost
res["price_unit"] = cost
elif line.account_move_line_id.purchase_line_id:
purchase_lines = line.account_move_line_id.purchase_line_id
moves = purchase_lines.mapped("move_ids")
if moves:
layers = moves.mapped("stock_valuation_layer_ids")
cost = layers[-1].unit_cost
# TODO: Should we be smart in the choice of the move?
res["price_unit"] = cost
return res
class ProcurementGroup(models.Model):
_inherit = "procurement.group"
rma_id = fields.Many2one(
comodel_name="rma.order", string="RMA", ondelete="set null"
)
rma_line_id = fields.Many2one(
comodel_name="rma.order.line", string="RMA line", ondelete="set null"
)

View File

@@ -1,4 +1,4 @@
# Copyright 2017-18 Eficent Business and IT Consulting Services S.L.
# Copyright 2017-2022 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo import api, models

View File

@@ -1,4 +1,4 @@
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# Copyright 2017-2022 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo import api, fields, models

View File

@@ -1,4 +1,4 @@
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
# Copyright 2017-2022 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo import _, api, fields, models

View File

@@ -1,4 +1,4 @@
# © 2017 Eficent Business and IT Consulting Services S.L.
# Copyright 2017-2022 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo import api, fields, models

View File

@@ -1,4 +1,4 @@
# © 2017 Eficent Business and IT Consulting Services S.L.
# Copyright 2017-2022 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo import _, api, fields, models

View File

@@ -1,4 +1 @@
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from . import test_rma_purchase

View File

@@ -1,4 +1,4 @@
# Copyright 2017-18 Eficent Business and IT Consulting Services S.L.
# Copyright 2017-2022 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo.fields import Datetime

View File

@@ -1,6 +1,3 @@
# © 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from . import rma_make_picking
from . import rma_add_purchase
from . import rma_order_line_make_purchase_order

View File

@@ -1,6 +1,5 @@
# © 2017 Eficent Business and IT Consulting Services S.L.
# Copyright 2017-2022 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError

View File

@@ -1,4 +1,4 @@
# © 2017 Eficent Business and IT Consulting Services S.L.
# Copyright 2017-2022 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo import api, fields, models

View File

@@ -1,5 +1,5 @@
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).
# Copyright 2017-2022 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from datetime import datetime