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

aaaaaaaa #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
30 changes: 30 additions & 0 deletions oaf_userfriendly_error_alert/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

# OAF User-Friendly Error Alert

This Odoo module enhances the user experience by providing user-friendly error alerts in the Point of Sale (POS) system.
Instead of displaying technical error messages for undefined errors, this module presents layman terms messages to the end users when they encounter issues while creating POS orders or customers.


## Features

-Custom error messages are provided in case of exceptions to guide the user on what went wrong and suggest the next steps to take.


## Installation

Add this module to the odoo environment

```bash
- Navigate to Apps
- Click Update Apps List
- Click Update
- Search for oaf_userfriendly_error_alert
- Right click on three dots top Right
- Install module
```



## Authors

- [@zelalemshiferaw](https://www.github.com/zelalemshiferaw)
1 change: 1 addition & 0 deletions oaf_userfriendly_error_alert/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions oaf_userfriendly_error_alert/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "OAF User-Friendly Error Alert",
"summary": "Displays user-friendly error messages for end users in the Point of Sale module.",
"version": "14.0.1",
"category": "Point Of Sale",
"website": "https://oneacrefund.org/",
"author": "Zelalem Shiferaw",
"license": "LGPL-3",
"description": """
This Odoo module enhances the user experience by providing user-friendly error alerts in the Point of Sale (POS) system.
Instead of displaying technical error messages, this module presents layman terms messages to the end users when they encounter issues while creating POS orders or customers.
""",
"depends": ["point_of_sale"]
}
1 change: 1 addition & 0 deletions oaf_userfriendly_error_alert/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import userfreindly_error_alert
35 changes: 35 additions & 0 deletions oaf_userfriendly_error_alert/models/userfreindly_error_alert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from odoo import api, fields, models, tools, _
from odoo.exceptions import UserError

# Define a custom model to extend the pos.order model
class ExtendedPosOrder(models.Model):
_inherit = 'pos.order'

# Override the create method to handle exceptions
@api.model
def create(self, vals):
try:
return super(ExtendedPosOrder, self).create(vals)
except Exception as e:
# User-friendly message to display in case of an exception
userfriendly_message = _("Oops! We couldn't save the sale at this time. Please try again."
" If the issue persists, please notify a manager or contact our support team for assistance. "
"Thank you for your understanding")

raise UserError(userfriendly_message)

# Define a custom model to extend the res.partner model
class ExtendedResPartner(models.Model):
_inherit = 'res.partner'

# Override the create method to handle exceptions
@api.model
def create(self, vals):
try:
return super(ExtendedResPartner, self).create(vals)
except Exception as e:
# User-friendly message to display in case of an exception
userfriendly_message = _("Apologies, we encountered an issue creating the customer profile on the POS system. "
"Please try again. If the problem persists, kindly contact our support team for assistance."
" Thank you for your patience")
raise UserError(userfriendly_message)
3 changes: 3 additions & 0 deletions oaf_userfriendly_error_alert/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import test_userfreindly_error_alert
from . import test_customer

43 changes: 43 additions & 0 deletions oaf_userfriendly_error_alert/tests/test_customer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from odoo.exceptions import ValidationError,UserError
from odoo.tests import tagged
from odoo.tests.common import TransactionCase

test_partner_complete_data = {
"name":"Test Client"
"firstName": "John",
"lastName": "Doe",
"nid": "xxxx-111-xxx",
"phoneNumber": "+254712345678"
}

@tagged("post_install")
class TestClientCreation(TransactionCase):

def setUp(self):
super(TestClient, self).setUp()
vals = {"name": "Test Client"}
self.test_partner = self.env["res.partner"].create(vals)

# Test for successful client creation
def test_create_clients_success(self):
vals = test_partner_complete_data
partner = self.env["res.partner"].create(vals)
self.assertEqual(partner.name, "Test Client")

# Test for invalid data types
def test_create_clients_invalid_data_types(self):
vals = {
"name": 1, # Invalid Name type
}
with self.assertRaises(ValidationError):
self.env["res.partner"].create(vals)

# Test for missing required fields
def test_create_clients_missing_required_fields(self):
vals = {
"function": "sales",
# Missing required fields like name
}
with self.assertRaises(ValidationError):
self.env["res.partner"].create(vals)

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from odoo.exceptions import ValidationError,UserError
from odoo.tests import tagged
from odoo.tests.common import TransactionCase

test_pos_order_complete_data = {
"company_id": 33,
"date_order": "2024-04-03 11:56:53",
"etr_state": "draft",
"name": "Order_Test",
"partner_id": 22814323,
"pos_reference": "Order Test",
"pricelist_id": 367,
"session_id": 13440,
}

@tagged("post_install")
class TestPOSCreation(TransactionCase):

def setUp(self):
super(TestPOS, self).setUp()
company_id = 33
order_id = self.env["pos.order"].create({
"company_id": 33,
"date_order": "2024-04-03 11:56:53",
"etr_state": "draft",
"name": "Order_Test",
"partner_id": 22814323,
"pos_reference": "Order Test",
"pricelist_id": 367,
"session_id": 13440,
}
)

product_id = self.env["product.product"].search([('company_id', '=', company_id)], limit=1).id
if not product_id:
product_id = self.env["product.product"].create({
'name': 'Testing_Products',
'categ_id': self.env['product.category'].search([], limit=1).id,
'uom_id': self.env['uom.uom'].search([], limit=1).id,
'uom_po_id': self.env['uom.uom'].search([], limit=1).id,
'company_id': company_id,
}).id
self.env["pos.order.line"].create({
"product_id": product_id,
"qty": 3,
"price_unit": 4,
"order_id": order_id.id,
})

# Test for successful POS creation
def test_create_clients_success(self):
vals = test_pos_order_complete_data
pos_order = self.env["pos.order"].create(vals)
self.assertEqual(pos_order.name, "Order_Test")


# Test for invalid data types
def test_create_pos_order_invalid_data_types(self):
vals = test_pos_order_complete_data
vals["partner_id"] = "char"
with self.assertRaises(ValidationError):
self.env["pos.order"].create(vals)

# Test for missing required fields
def test_create_pos_order_missing_required_fields(self):
vals = {
"partner_id": 22814323,
# Missing required fields like session_id
}
with self.assertRaises(ValidationError):
self.env["pos.order"].create(vals)

# Test for dependency resolution
def test_create_pos_order_dependency_resolution(self):
vals = test_partner_complete_data
del vals["partner_id"] # Missing Partner_id data
with self.assertRaises(ValidationError):
self.env["pos.order"].create(vals)


Loading