diff --git a/rma_account_product_warranty/README.rst b/rma_account_product_warranty/README.rst new file mode 100644 index 000000000..57766362b --- /dev/null +++ b/rma_account_product_warranty/README.rst @@ -0,0 +1,30 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License AGPL-3 + +============================ +RMA Account Product Warranty +============================ + +This module integrates RMA with product warranties + +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. + +Credits +======= + +Contributors +------------ + +* Aaron Henriquez + + +Maintainer +---------- + +This module is maintained by ForgeFlow diff --git a/rma_account_product_warranty/__init__.py b/rma_account_product_warranty/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/rma_account_product_warranty/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/rma_account_product_warranty/__manifest__.py b/rma_account_product_warranty/__manifest__.py new file mode 100644 index 000000000..513fb0b55 --- /dev/null +++ b/rma_account_product_warranty/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2023 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +{ + "name": "RMA Product Warranty", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "category": "RMA", + "summary": "Integrates RMA Account with Product Warranty", + "author": "ForgeFlow", + "website": "https://github.com/ForgeFlow/stock-rma", + "depends": ["rma_account", "rma_product_warranty"], + "installable": True, +} diff --git a/rma_account_product_warranty/models/__init__.py b/rma_account_product_warranty/models/__init__.py new file mode 100644 index 000000000..0ec42a97c --- /dev/null +++ b/rma_account_product_warranty/models/__init__.py @@ -0,0 +1 @@ +from . import rma_order_line diff --git a/rma_account_product_warranty/models/rma_order_line.py b/rma_account_product_warranty/models/rma_order_line.py new file mode 100644 index 000000000..70c79af89 --- /dev/null +++ b/rma_account_product_warranty/models/rma_order_line.py @@ -0,0 +1,38 @@ +# Copyright 2023 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from dateutil.relativedelta import relativedelta + +from odoo import models + + +class RmaOrderLine(models.Model): + + _inherit = "rma.order.line" + + def _compute_warranty_end_date(self): + res = super()._compute_warranty_end_date() + for rec in self: + warranty = rec.product_id.warranty + if rec.account_move_line_id and warranty: + if rec.product_id.warranty_type == "day": + rec.warranty_end_date = ( + rec.account_move_line_id.date + relativedelta(days=warranty) + ) + elif rec.product_id.warranty_type == "week": + rec.warranty_end_date = ( + rec.account_move_line_id.date + relativedelta(weeks=warranty) + ) + elif rec.product_id.warranty_type == "month": + rec.warranty_end_date = ( + rec.account_move_line_id.date + relativedelta(months=warranty) + ) + elif rec.product_id.warranty_type == "year": + rec.warranty_end_date = ( + rec.account_move_line_id.date + relativedelta(years=warranty) + ) + elif rec.sale_line_id and rec.sale_line_id.invoice_lines: + rec.warranty_end_date = rec.sale_line_id.invoice_lines[ + 0 + ].date + relativedelta(years=warranty) + return res diff --git a/rma_product_warranty/README.rst b/rma_product_warranty/README.rst new file mode 100644 index 000000000..f116559a1 --- /dev/null +++ b/rma_product_warranty/README.rst @@ -0,0 +1,29 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License AGPL-3 + +==================== +RMA Product Warranty +==================== + +This module integrates RMA with product warranties +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. + +Credits +======= + +Contributors +------------ + +* Aaron Henriquez + + +Maintainer +---------- + +This module is maintained by ForgeFlow diff --git a/rma_product_warranty/__init__.py b/rma_product_warranty/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/rma_product_warranty/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/rma_product_warranty/__manifest__.py b/rma_product_warranty/__manifest__.py new file mode 100644 index 000000000..30f160455 --- /dev/null +++ b/rma_product_warranty/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2023 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +{ + "name": "RMA Product Warranty", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "category": "RMA", + "summary": "Integrates RMA Product Warranty", + "author": "ForgeFlow", + "website": "https://github.com/ForgeFlow/stock-rma", + "depends": ["rma", "product_warranty"], + "data": ["views/rma_order_line_view.xml"], + "installable": True, +} diff --git a/rma_product_warranty/models/__init__.py b/rma_product_warranty/models/__init__.py new file mode 100644 index 000000000..0ec42a97c --- /dev/null +++ b/rma_product_warranty/models/__init__.py @@ -0,0 +1 @@ +from . import rma_order_line diff --git a/rma_product_warranty/models/rma_order_line.py b/rma_product_warranty/models/rma_order_line.py new file mode 100644 index 000000000..8a4686acf --- /dev/null +++ b/rma_product_warranty/models/rma_order_line.py @@ -0,0 +1,49 @@ +# Copyright 2023 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html) + +from datetime import datetime + +from dateutil.relativedelta import relativedelta + +from odoo import fields, models + + +class RmaOrderLine(models.Model): + + _inherit = "rma.order.line" + + warranty_end_date = fields.Date(compute="_compute_warranty_end_date") + under_warranty = fields.Boolean(compute="_compute_under_warranty") + + def _compute_warranty_end_date(self): + for rec in self: + warranty = rec.product_id.warranty + if rec.reference_move_id and warranty: + if rec.product_id.warranty_type == "day": + rec.warranty_end_date = rec.reference_move_id.date + relativedelta( + days=warranty + ) + elif rec.product_id.warranty_type == "week": + rec.warranty_end_date = rec.reference_move_id.date + relativedelta( + weeks=warranty + ) + elif rec.product_id.warranty_type == "month": + rec.warranty_end_date = rec.reference_move_id.date + relativedelta( + months=warranty + ) + elif rec.product_id.warranty_type == "year": + rec.warranty_end_date = rec.reference_move_id.date + relativedelta( + years=warranty + ) + else: + rec.warranty_end_date = False + else: + rec.warranty_end_date = False + + def _compute_under_warranty(self): + today = datetime.today() + for rec in self: + if not rec.warranty_end_date: + rec.under_warranty = True + else: + rec.under_warranty = rec.warranty_end_date >= today.date() diff --git a/rma_product_warranty/views/rma_order_line_view.xml b/rma_product_warranty/views/rma_order_line_view.xml new file mode 100644 index 000000000..b6eb4f1b8 --- /dev/null +++ b/rma_product_warranty/views/rma_order_line_view.xml @@ -0,0 +1,15 @@ + + + + + rma.order.line.warranty.form + rma.order.line + + + + + + + + + diff --git a/setup/rma_account_product_warranty/odoo/addons/rma_account_product_warranty b/setup/rma_account_product_warranty/odoo/addons/rma_account_product_warranty new file mode 120000 index 000000000..01c8869fd --- /dev/null +++ b/setup/rma_account_product_warranty/odoo/addons/rma_account_product_warranty @@ -0,0 +1 @@ +../../../../rma_account_product_warranty \ No newline at end of file diff --git a/setup/rma_account_product_warranty/setup.py b/setup/rma_account_product_warranty/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/rma_account_product_warranty/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/setup/rma_product_warranty/odoo/addons/rma_product_warranty b/setup/rma_product_warranty/odoo/addons/rma_product_warranty new file mode 120000 index 000000000..874569134 --- /dev/null +++ b/setup/rma_product_warranty/odoo/addons/rma_product_warranty @@ -0,0 +1 @@ +../../../../rma_product_warranty \ No newline at end of file diff --git a/setup/rma_product_warranty/setup.py b/setup/rma_product_warranty/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/rma_product_warranty/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)