diff --git a/rma_purchase/__init__.py b/rma_purchase/__init__.py index f3284a96..aee8895e 100644 --- a/rma_purchase/__init__.py +++ b/rma_purchase/__init__.py @@ -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 diff --git a/rma_purchase/__manifest__.py b/rma_purchase/__manifest__.py index fcda2e51..153e14d6 100644 --- a/rma_purchase/__manifest__.py +++ b/rma_purchase/__manifest__.py @@ -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, } diff --git a/rma_purchase/models/__init__.py b/rma_purchase/models/__init__.py index d41e378c..5edaa9af 100644 --- a/rma_purchase/models/__init__.py +++ b/rma_purchase/models/__init__.py @@ -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 diff --git a/rma_purchase/models/procurement.py b/rma_purchase/models/procurement.py new file mode 100644 index 00000000..854181f5 --- /dev/null +++ b/rma_purchase/models/procurement.py @@ -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" + ) diff --git a/rma_purchase/models/purchase_order.py b/rma_purchase/models/purchase_order.py index 37d9f784..4d81bc04 100644 --- a/rma_purchase/models/purchase_order.py +++ b/rma_purchase/models/purchase_order.py @@ -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 diff --git a/rma_purchase/models/purchase_order_line.py b/rma_purchase/models/purchase_order_line.py index 70444eee..4962d861 100644 --- a/rma_purchase/models/purchase_order_line.py +++ b/rma_purchase/models/purchase_order_line.py @@ -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 diff --git a/rma_purchase/models/rma_operation.py b/rma_purchase/models/rma_operation.py index 5ee52512..6f03753c 100644 --- a/rma_purchase/models/rma_operation.py +++ b/rma_purchase/models/rma_operation.py @@ -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 diff --git a/rma_purchase/models/rma_order.py b/rma_purchase/models/rma_order.py index 286276f6..503fdd5a 100644 --- a/rma_purchase/models/rma_order.py +++ b/rma_purchase/models/rma_order.py @@ -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 diff --git a/rma_purchase/models/rma_order_line.py b/rma_purchase/models/rma_order_line.py index 2015d4d9..319ac080 100644 --- a/rma_purchase/models/rma_order_line.py +++ b/rma_purchase/models/rma_order_line.py @@ -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 diff --git a/rma_purchase/tests/__init__.py b/rma_purchase/tests/__init__.py index 061a9ecc..c7f1b5f2 100644 --- a/rma_purchase/tests/__init__.py +++ b/rma_purchase/tests/__init__.py @@ -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 diff --git a/rma_purchase/tests/test_rma_purchase.py b/rma_purchase/tests/test_rma_purchase.py index c9cd65f6..558d2389 100644 --- a/rma_purchase/tests/test_rma_purchase.py +++ b/rma_purchase/tests/test_rma_purchase.py @@ -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 diff --git a/rma_purchase/wizards/__init__.py b/rma_purchase/wizards/__init__.py index 73c6279c..632e2e5b 100644 --- a/rma_purchase/wizards/__init__.py +++ b/rma_purchase/wizards/__init__.py @@ -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 diff --git a/rma_purchase/wizards/rma_add_purchase.py b/rma_purchase/wizards/rma_add_purchase.py index 143ea44e..4ba17d1c 100644 --- a/rma_purchase/wizards/rma_add_purchase.py +++ b/rma_purchase/wizards/rma_add_purchase.py @@ -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 diff --git a/rma_purchase/wizards/rma_make_picking.py b/rma_purchase/wizards/rma_make_picking.py index f1694bf3..36f16ba6 100644 --- a/rma_purchase/wizards/rma_make_picking.py +++ b/rma_purchase/wizards/rma_make_picking.py @@ -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 diff --git a/rma_purchase/wizards/rma_order_line_make_purchase_order.py b/rma_purchase/wizards/rma_order_line_make_purchase_order.py index 5bda01fe..ce702041 100644 --- a/rma_purchase/wizards/rma_order_line_make_purchase_order.py +++ b/rma_purchase/wizards/rma_order_line_make_purchase_order.py @@ -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