Skip to content

Commit

Permalink
[ADD] rma_website
Browse files Browse the repository at this point in the history
  • Loading branch information
max3903 committed Sep 9, 2021
1 parent c2d3807 commit fe274bb
Show file tree
Hide file tree
Showing 23 changed files with 896 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ repos:
# update the NOT INSTALLABLE ADDONS section above
- id: oca-update-pre-commit-excluded-addons
- id: oca-fix-manifest-website
args: ["https://github.com/OCA/https://github.com/ForgeFlow/stock-rma"]
args: ["https://github.com/ForgeFlow/stock-rma"]
- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ score=n

[ODOOLINT]
readme_template_url="https://github.com/OCA/maintainer-tools/blob/master/template/module/README.rst"
manifest_required_authors=Odoo Community Association (OCA)
manifest_required_authors=ForgeFlow
manifest_required_keys=license
manifest_deprecated_keys=description,active
license_allowed=AGPL-3,GPL-2,GPL-2 or any later version,GPL-3,GPL-3 or any later version,LGPL-3
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc-mandatory
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ score=n

[ODOOLINT]
readme_template_url="https://github.com/OCA/maintainer-tools/blob/master/template/module/README.rst"
manifest_required_authors=Odoo Community Association (OCA)
manifest_required_authors=ForgeFlow
manifest_required_keys=license
manifest_deprecated_keys=description,active
license_allowed=AGPL-3,GPL-2,GPL-2 or any later version,GPL-3,GPL-3 or any later version,LGPL-3
Expand Down
2 changes: 1 addition & 1 deletion rma/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"summary": "Introduces the return merchandise authorization (RMA) process "
"in odoo",
"author": "ForgeFlow",
"website": "https://github.com/OCA/https://github.com/ForgeFlow/stock-rma",
"website": "https://github.com/ForgeFlow/stock-rma",
"depends": ["stock", "mail", "web"],
"demo": ["demo/stock_demo.xml"],
"data": [
Expand Down
2 changes: 1 addition & 1 deletion rma_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"category": "RMA",
"summary": "Integrates RMA with Invoice Processing",
"author": "ForgeFlow",
"website": "https://github.com/OCA/https://github.com/ForgeFlow/stock-rma",
"website": "https://github.com/ForgeFlow/stock-rma",
"depends": ["stock_account", "rma"],
"data": [
"security/ir.model.access.csv",
Expand Down
2 changes: 1 addition & 1 deletion rma_purchase/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"summary": "RMA from PO",
"license": "LGPL-3",
"author": "Eficent, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/https://github.com/ForgeFlow/stock-rma",
"website": "https://github.com/ForgeFlow/stock-rma",
"depends": ["rma_account", "purchase"],
"data": [
"wizards/rma_order_line_make_purchase_order_view.xml",
Expand Down
2 changes: 1 addition & 1 deletion rma_repair/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"category": "RMA",
"summary": "Links RMA with Repairs.",
"author": "ForgeFlow S.L., Odoo Community Association (OCA)",
"website": "https://github.com/OCA/https://github.com/ForgeFlow/stock-rma",
"website": "https://github.com/ForgeFlow/stock-rma",
"depends": ["rma_account", "repair_refurbish"],
"data": [
"security/ir.model.access.csv",
Expand Down
2 changes: 1 addition & 1 deletion rma_sale/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"category": "RMA",
"summary": "Links RMA with Sales Orders",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/https://github.com/ForgeFlow/stock-rma",
"website": "https://github.com/ForgeFlow/stock-rma",
"depends": ["rma_account", "sale_stock"],
"data": [
"security/ir.model.access.csv",
Expand Down
46 changes: 46 additions & 0 deletions rma_website/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
===========
RMA Website
===========

.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3

This module allows you to expose the list of RMA groups on the portal with their name
and state.

**Table of contents**

.. contents::
:local:

Usage
=====

* Go to the website
* Go to My Account > RMA
* Create a RMA by selecting products and entering the quantity returned
* Submit your RMA and upload pictures of the damage

Credits
=======

Authors
~~~~~~~

* Open Source Integrators <contact@opensourceintegrators.com>

Contributors
~~~~~~~~~~~~

* Ammar Officewala <aofficewala@opensourceintegrators.com>
* Melody Fetterly <mfetterly@opensourceintegrators.com>
* Raphael Lee <rlee@opensourceintegrators.com>
* Maxime Chambreuil <mchambreuil@opensourceintegrators.com>

Maintainers
~~~~~~~~~~~

This module is maintained by ForgeFlow.

This module is part of the `ForgeFlow/stock-rma <https://github.com/ForgeFlow/stock-rma>`_ project on GitHub.
4 changes: 4 additions & 0 deletions rma_website/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2021 Open Source Integrators (https://www.opensourceintegrators.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from . import controllers
from . import models
19 changes: 19 additions & 0 deletions rma_website/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (C) 2021 Open Source Integrators (https://www.opensourceintegrators.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
{
"name": "RMA Website",
"version": "14.0.1.0.0",
"license": "LGPL-3",
"summary": "Allow Portal users to create RMA",
"author": "Open Source Integrators",
"maintainer": "ForgeFlow",
"website": "https://github.com/ForgeFlow/stock-rma",
"depends": ["portal", "rma_account"],
"data": [
"security/ir.model.access.csv",
"security/ir.rule.csv",
"views/portal_view.xml",
"views/assets.xml",
],
"maintainers": ["ursais"],
}
3 changes: 3 additions & 0 deletions rma_website/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (C) 2021 Open Source Integrators (https://www.opensourceintegrators.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from . import main
198 changes: 198 additions & 0 deletions rma_website/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
# Copyright (C) 2021 Open Source Integrators (https://www.opensourceintegrators.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from datetime import datetime

import werkzeug

from odoo import http
from odoo.exceptions import AccessError, MissingError
from odoo.http import request

from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager


class CustomerPortal(CustomerPortal):
def _prepare_home_portal_values(self, counters):
values = super()._prepare_home_portal_values(counters)
if "rma_order_count" in counters:
values["rma_order_count"] = (
request.env["rma.order"].search_count([])
if request.env["rma.order"].check_access_rights(
"read", raise_exception=False
)
else 0
)
return values

@http.route(
["/my/rma/order", "/my/rma/order/<int:page>"],
type="http",
auth="user",
website=True,
)
def portal_my_orders_lines(
self, page=1, date_begin=None, date_end=None, sortby=None, **kw
):
values = self._prepare_portal_layout_values()
RmaOrder = request.env["rma.order"]
domain = []

searchbar_sortings = {}

sort_order = ""

if date_begin and date_end:
domain += [
("create_date", ">", date_begin),
("create_date", "<=", date_end),
]

# count for pager
order_count = RmaOrder.search_count(domain)
# pager
pager = portal_pager(
url="/my/rma/order",
url_args={"date_begin": date_begin, "date_end": date_end, "sortby": sortby},
total=order_count,
page=page,
step=self._items_per_page,
)
# content according to pager
orders = RmaOrder.search(
domain, order=sort_order, limit=self._items_per_page, offset=pager["offset"]
)
request.session["my_rma_line_history"] = orders.ids[:100]

values.update(
{
"date": date_begin,
"orders": orders.sudo(),
"page_name": "rma_order",
"pager": pager,
"default_url": "/my/rma/order",
"searchbar_sortings": searchbar_sortings,
"sortby": sortby,
}
)
return request.render("rma_website.rma_order_portal", values)

@http.route(
[
"/rma/order/<int:ticket_id>",
"/rma/order/<int:ticket_id>/<access_token>",
"/rma/order/<int:ticket_id>",
"/rma/order/<int:ticket_id>/<access_token>",
],
type="http",
auth="public",
website=True,
)
def rma_order_view(self, ticket_id=None, access_token=None, **kw):
try:
order_sudo = self._document_check_access(
"rma.order", ticket_id, access_token
)
except (AccessError, MissingError):
return request.redirect("/my")

values = self._rma_order_get_page_view_values(order_sudo, access_token, **kw)

return request.render("rma_website.rma_order_tmaplate_view", values)

def _rma_order_get_page_view_values(self, order_sudo, access_token, **kwargs):
values = {
"page_name": "rma_order",
"rma_order": order_sudo,
}
return self._get_page_view_values(
order_sudo, access_token, values, "my_rma_line_history", False, **kwargs
)

@http.route("/rma/order/new", type="http", auth="public", website=True)
def rma_counters(self, **kw):
customer_ids = request.env["res.partner"].search([("customer_rank", ">", 0)])
product_ids = request.env["product.product"].search([])
lot_ids = request.env["stock.production.lot"].search([])
operation_ids = request.env["rma.operation"].search([])
operation_id = request.env.ref(
"rma.rma_operation_customer_replace", raise_if_not_found=False
)
values = {
"customer_ids": customer_ids,
"product_ids": product_ids,
"lot_ids": lot_ids,
"operation_ids": operation_ids,
"operation_id": operation_id,
}
return request.render("rma_website.rma_customer_portal", values)

@http.route("/create/group", type="http", auth="public", website=True)
def full_url_redirect(self, **post):
order_obj = request.env["rma.order"]

customer_id = post.get("customer", False)
order_date = post.get("order_date", False)
info = post.get("info", False)
order_date = datetime.strptime(order_date, "%Y-%m-%dT%H:%M")

products = post.get("products", False)
lots = post.get("lots", False)
references = post.get("references", False)
operations = post.get("operations", False)
return_qty = post.get("return_qty", False)
price_units = post.get("price_units", False)
line_ids = []
vals = order_obj.default_get(
["in_warehouse_id", "company_id", "out_warehouse_id"]
)
if products and references and operations and return_qty and price_units:
products = products.split(",")
if lots:
lots = lots.split(",")

references = references.split(",")
operations = operations.split(",")
return_qty = return_qty.split(",")
price_units = price_units.split(",")
for i in range(0, len(operations)):
product_id = request.env["product.product"].browse(int(products[i]))
operation_id = request.env["rma.operation"].browse(int(operations[i]))
warehouse_id = request.env["stock.warehouse"].browse(
int(vals.get("in_warehouse_id"))
)

location_id = operation_id.location_id.id or warehouse_id.lot_rma_id.id
line_ids.append(
(
0,
0,
{
"partner_id": int(customer_id),
"product_id": products[i],
"uom_id": product_id.uom_id.id,
"lot_id": lots and lots[i],
"name": references[i],
"operation_id": operations[i],
"product_qty": return_qty[i],
"price_unit": price_units[i],
"in_route_id": operation_id.in_route_id.id,
"out_route_id": operation_id.out_route_id.id,
"in_warehouse_id": vals.get("in_warehouse_id"),
"out_warehouse_id": operation_id.out_warehouse_id.id,
"location_id": location_id,
},
)
)

vals.update(
{
"partner_id": int(customer_id),
"date_rma": order_date,
"comment": info,
"rma_line_ids": line_ids,
"assign_to": False,
"message_partner_ids": [(6, 0, [int(customer_id)])],
}
)
order_obj.sudo().create(vals)
return werkzeug.utils.redirect("/my/rma/order", 301)
1 change: 1 addition & 0 deletions rma_website/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import rma_order
12 changes: 12 additions & 0 deletions rma_website/models/rma_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from odoo import models


class RmaOrder(models.Model):
_name = "rma.order"
_inherit = [
"rma.order",
"portal.mixin",
"mail.thread",
"mail.activity.mixin",
"utm.mixin",
]
5 changes: 5 additions & 0 deletions rma_website/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"id","name","model_id/id","group_id/id","perm_read","perm_write","perm_create","perm_unlink"
"access_rma_order_line_portal","rma.order.line.portal","rma.model_rma_order_line","base.group_portal",1,0,0,0
"access_rma_order_portal","rma.order.portal","rma.model_rma_order","base.group_portal",1,0,0,0
"access_rma_operation_portal","rma.operation.portal","rma_account.model_rma_operation","base.group_portal",1,0,0,0
"access_stock_production_lot_portal","stock.production.lot.portal","stock.model_stock_production_lot","base.group_portal",1,0,0,0
3 changes: 3 additions & 0 deletions rma_website/security/ir.rule.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id/id,groups/id,domain_force,perm_read,perm_write,perm_create,perm_unlink
rule_portal_rma_group,Portal RMA Group,rma.model_rma_order,base.group_portal,"[('message_partner_ids', 'child_of', [user.commercial_partner_id.id])]",1,1,1,0
rule_portal_rma,Portal RMA,rma.model_rma_order_line,base.group_portal,"[('message_partner_ids', 'child_of', [user.commercial_partner_id.id])]",1,1,1,0
Binary file added rma_website/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit fe274bb

Please sign in to comment.