Skip to content

Commit

Permalink
Merge pull request #216 from efeone/aumms_006
Browse files Browse the repository at this point in the history
feat : Created Qr Code for item and created new doctype item category
  • Loading branch information
muhammadmp authored Feb 16, 2024
2 parents cbaaed1 + 35d56ca commit 2b85408
Show file tree
Hide file tree
Showing 12 changed files with 641 additions and 171 deletions.
547 changes: 407 additions & 140 deletions aumms/aumms/custom/item.json

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions aumms/aumms/custom/item_barcode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"custom_fields": [],
"custom_perms": [],
"doctype": "Item Barcode",
"links": [],
"property_setters": [
{
"_assign": null,
"_comments": null,
"_liked_by": null,
"_user_tags": null,
"creation": "2024-02-03 11:01:51.263147",
"default_value": null,
"doc_type": "Item Barcode",
"docstatus": 0,
"doctype_or_field": "DocField",
"field_name": "barcode",
"idx": 0,
"is_system_generated": 1,
"modified": "2024-02-03 11:01:51.263147",
"modified_by": "Administrator",
"module": null,
"name": "Item Barcode-barcode-hidden",
"owner": "Administrator",
"property": "hidden",
"property_type": "Check",
"row_name": null,
"value": "0"
}
],
"sync_on_migrate": 1
}
91 changes: 91 additions & 0 deletions aumms/aumms/doc_events/item.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import os
import io
import json
import frappe
from frappe import _
from datetime import date
from pyqrcode import create
from base64 import b64encode
from pyqrcode import create as qr_create
from frappe.utils.data import get_url_to_form
from aumms.aumms.utils import get_conversion_factor
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields

@frappe.whitelist()
def validate_item(doc, method):
Expand Down Expand Up @@ -128,3 +137,85 @@ def get_existing_uoms(uoms):
for uom in uoms:
uoms_list.append(uom.uom)
return uoms_list

def create_qr(doc, method=None):
# Creating a fied for QR code if it doesn't exist
if not hasattr(doc, "item_qr"):
create_custom_fields(
{
doc.doctype: [
dict(
fieldname="item_qr",
label="Item QR",
fieldtype="Attach Image",
read_only=1,
no_copy=1,
# hidden=1,
)
]
}
)

# Checking if a qr code is already generated
qr_code = doc.get("item_qr")
if qr_code and frappe.db.exists({"doctype": "File", "file_url": qr_code}):
return


doc_url = get_si_json(doc)

# Generating QR image
qr_image = io.BytesIO()
url = create(doc_url, error="L")
url.png(qr_image, scale = 2, quiet_zone=1)

name = frappe.generate_hash(doc.name, 5)

# Uploading the QR and attaching it to the document
filename = f"QRCode-{name}.png".replace(os.path.sep, "__")
_file = frappe.get_doc(
{
"doctype": "File",
"file_name": filename,
"is_private": 0,
"content": qr_image.getvalue(),
"attached_to_doctype": doc.get("doctype"),
"attached_to_name": doc.get("name"),
"attached_to_field": "item_qr",
}
)

_file.save()

# assigning to document
doc.db_set("item_qr", _file.file_url)
doc.notify_update()

def get_si_json(doc):
# Define the list of essential fields
essential_fields = [
"item_code",
"item_name",
"item_group",
"custom_company",
"custom_item_class",
"custom_parent_item_group",
]

# Create a dictionary to store the field values
item_data = {}

# Extract the field values from the document object
for field in essential_fields:
value = doc.get(field)

# Convert datetime.date objects to string representation
if isinstance(value, date):
value = value.strftime("%Y-%m-%d")

item_data[field] = value

# Convert the dictionary to JSON
json_data = json.dumps(item_data, indent=4)

return json_data
Empty file.
8 changes: 8 additions & 0 deletions aumms/aumms/doctype/item_category/item_category.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2024, efeone and contributors
// For license information, please see license.txt

// frappe.ui.form.on("Item Category", {
// refresh(frm) {

// },
// });
44 changes: 44 additions & 0 deletions aumms/aumms/doctype/item_category/item_category.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "field:item_category",
"creation": "2024-02-16 11:29:28.576791",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"item_category"
],
"fields": [
{
"fieldname": "item_category",
"fieldtype": "Data",
"label": "Item Category",
"unique": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-02-16 11:32:26.573014",
"modified_by": "Administrator",
"module": "AuMMS",
"name": "Item Category",
"naming_rule": "By fieldname",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
9 changes: 9 additions & 0 deletions aumms/aumms/doctype/item_category/item_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2024, efeone and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document


class ItemCategory(Document):
pass
9 changes: 9 additions & 0 deletions aumms/aumms/doctype/item_category/test_item_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2024, efeone and Contributors
# See license.txt

# import frappe
from frappe.tests.utils import FrappeTestCase


class TestItemCategory(FrappeTestCase):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"fieldname": "net_weight",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Net Weight"
"label": "Net Weight",
"read_only": 1
},
{
"fieldname": "amount",
Expand All @@ -62,6 +63,7 @@
"label": "Stone Weight"
},
{
"depends_on": "eval:doc.stone",
"fieldname": "stone_charge",
"fieldtype": "Currency",
"in_list_view": 1,
Expand All @@ -71,7 +73,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-02-14 12:45:03.190279",
"modified": "2024-02-16 12:40:10.378507",
"modified_by": "Administrator",
"module": "AuMMS",
"name": "Purchase Item Details",
Expand All @@ -80,4 +82,4 @@
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
}
38 changes: 21 additions & 17 deletions aumms/aumms/doctype/purchase_tool/purchase_tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@
// For license information, please see license.txt

frappe.ui.form.on("Purchase Tool", {
refresh : function(frm){
if(frm.doc.has_stone == 1){
frm.fields_dict.item_details.grid.update_docfield_property('stone', 'hidden', 1);
frm.fields_dict.item_details.grid.update_docfield_property('stone_weight', 'hidden', 1);
frm.fields_dict.item_details.grid.update_docfield_property('stone_charge', 'hidden', 1);
}
else{
frm.fields_dict.item_details.grid.update_docfield_property('stone', 'hidden', 0);
frm.fields_dict.item_details.grid.update_docfield_property('stone_weight', 'hidden', 0);
frm.fields_dict.item_details.grid.update_docfield_property('stone_charge', 'hidden', 0);
}
}

// refresh : function(frm){}

});

frappe.ui.form.on("Purchase Item Details",{
item_details_add : function(frm, cdt, cdn){
let child = locals[cdt][cdn]
if(frm.doc.stone){
frappe.ui.form.on("Purchase Item Details", {
item_details_add: function(frm, cdt, cdn) {
let child = locals[cdt][cdn];
if (frm.doc.stone) {
frappe.model.set_value(child.doctype, child.name, 'stone', frm.doc.stone);
}
}
},
stone_weight: function(frm, cdt, cdn) {
let d = locals[cdt][cdn];
if (frm.doc.has_stone) {
let net_weight = d.gold_weight + d.stone_weight;
frappe.model.set_value(cdt, cdn, 'net_weight', net_weight);
}
},
gold_weight: function(frm, cdt, cdn) {
let d = locals[cdt][cdn];
if (!frm.doc.has_stone) {
frappe.model.set_value(cdt, cdn, 'net_weight', d.gold_weight);
}
},
});
21 changes: 11 additions & 10 deletions aumms/aumms/doctype/purchase_tool/purchase_tool.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
"engine": "InnoDB",
"field_order": [
"section_break_urwi",
"supplier",
"item_category",
"item_type",
"item_group",
"item_set",
"supplier",
"column_break_pnvl",
"board_rate",
"date",
"stone",
"has_stone",
"stone",
"section_break_vxux",
"item_details",
"amended_from"
Expand Down Expand Up @@ -92,23 +92,24 @@
"label": "Date",
"reqd": 1
},
{
"fieldname": "item_set",
"fieldtype": "Data",
"label": "Item Set"
},
{
"fieldname": "board_rate",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Board Rate",
"reqd": 1
},
{
"fieldname": "item_category",
"fieldtype": "Link",
"label": "Item Category",
"options": "Item Category"
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2024-02-14 12:52:10.709714",
"modified": "2024-02-16 11:39:30.426147",
"modified_by": "Administrator",
"module": "AuMMS",
"name": "Purchase Tool",
Expand All @@ -132,4 +133,4 @@
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
}
5 changes: 4 additions & 1 deletion aumms/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@
doc_events = {
'Item': {
'validate': 'aumms.aumms.doc_events.item.validate_item',
'before_save': 'aumms.aumms.doc_events.item.check_conversion_factor_for_uom',
'before_save': [
'aumms.aumms.doc_events.item.check_conversion_factor_for_uom',
'aumms.aumms.doc_events.item.create_qr'
],
'on_update': 'aumms.aumms.doc_events.item.update_uoms_table'
},
'Purchase Receipt': {
Expand Down

0 comments on commit 2b85408

Please sign in to comment.