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

Ajmal changes #424

Merged
merged 15 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
21 changes: 12 additions & 9 deletions aumms/aumms/doc_events/item.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import os
import io
import json
import frappe
from frappe import _
import os
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

import frappe
from aumms.aumms.utils import get_conversion_factor
from frappe import _
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
from pyqrcode import create


@frappe.whitelist()
def validate_item(doc, method):
Expand Down Expand Up @@ -41,8 +40,12 @@ def uom_is_a_purity_uom(uom):
uom: name of uom document
output: a message iff uom is not a purity uom
"""
if not frappe.db.exists('UOM', {'name': uom, 'is_purity_uom': 1}):
frappe.throw(_('{} is not a purity uom'.format(uom)))
pass
#
# This is kept in pass because the integration of Nos as stock qty is ongoing
#
# if not frappe.db.exists('UOM', {'name': uom, 'is_purity_uom': 1}):
# frappe.throw(_('{} is not a purity uom'.format(uom)))

@frappe.whitelist()
def get_purity_uom():
Expand Down
80 changes: 80 additions & 0 deletions aumms/aumms/doc_events/stock_reconciliation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import frappe
from frappe import _


def get_balance_qty(aumms_item_doc):
filters = {
"item_type": aumms_item_doc.item_type,
"purity": aumms_item_doc.purity,
"stock_uom": aumms_item_doc.weight_uom,
"is_cancelled": 0,
}
return frappe.db.get_value("Metal Ledger Entry", filters, "balance_qty") or 0


def insert_metal_ledger_entry(
doc, item, aumms_item_doc, balance_qty, is_reversal=False
):
fields = {
"doctype": "Metal Ledger Entry",
"posting_date": doc.posting_date,
"posting_time": doc.posting_time,
"voucher_type": doc.doctype,
"voucher_no": doc.name,
"company": frappe.defaults.get_defaults().company,
"item_code": item.item_code,
"item_name": item.item_name,
"stock_uom": aumms_item_doc.weight_uom,
"purity": aumms_item_doc.purity,
"purity_percentage": aumms_item_doc.purity_percentage,
"board_rate": item.valuation_rate,
"batch_no": item.batch_no,
"item_type": aumms_item_doc.item_type,
"balance_qty": balance_qty
+ (
aumms_item_doc.gold_weight
if not is_reversal
else -aumms_item_doc.gold_weight
),
"amount": item.amount if not is_reversal else -item.amount,
"incoming_rate" if not is_reversal else "outgoing_rate": item.valuation_rate,
"entry_type": "Opening Stock" if doc.purpose == 'Opening Stock' else None
}


frappe.get_doc(fields).insert(ignore_permissions=1)


def process_metal_ledger(doc, is_reversal=False):
if not doc.keep_metal_ledger:
return

ledger_created = False
for item in doc.items:
aumms_item_doc = frappe.get_doc("AuMMS Item", item.item_code)
balance_qty = get_balance_qty(aumms_item_doc)

insert_metal_ledger_entry(doc, item, aumms_item_doc, balance_qty, is_reversal)
ledger_created = True

if ledger_created:
action = _("reversed") if is_reversal else _("created")
frappe.msgprint(
_("Metal Ledger Entry is {0}.").format(action),
indicator="green" if not is_reversal else "red",
alert=1,
)


def create_mle_against_sr(doc, method=None):
"""
Method to create metal ledger entries on submit.
"""
process_metal_ledger(doc)


def reverse_mle_against_sr(doc, method=None):
"""
Method to reverse metal ledger entries on cancel.
"""
process_metal_ledger(doc, is_reversal=True)
58 changes: 58 additions & 0 deletions aumms/aumms/doctype/aumms_item/aumms_item.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,61 @@ let calculate_stone_weight_and_charge = function(frm){
frm.set_value('stone_weight', stone_weight);
frm.set_value('stone_charge', stone_charge);
}


// Button to create Stock reconciliation

frappe.ui.form.on('AuMMS Item', {
refresh: function(frm) {
frm.page.set_primary_action(__('Create'), function() {
// Remove any existing "Create Opening Stock" button
frm.remove_custom_button('Create Opening Stock');

// Add "Create Opening Stock" button
frm.add_custom_button(__('Create Opening Stock'), function() {
// Open a dialog to select the Board Rate
let dialog = new frappe.ui.Dialog({
title: __('Select Board Rate'),
fields: [
{
label: __('Board Rate'),
fieldname: 'board_rate',
fieldtype: 'Link',
options: 'Board Rate',
reqd: true
}
],
primary_action_label: __('Create Opening Stock'),
primary_action: function(data) {
dialog.hide(); // Hide dialog after selection

// Call the server-side function to create the opening stock
frappe.call({
method: 'aumms.aumms.doctype.aumms_item.aumms_item.create_opening_stock',
args: {
item_list: frm.doc.name,
board_rate: data.board_rate
},
freeze: true,
freeze_message: __('Creating Opening Stock...'),
callback: function(r) {
if (!r.exc) {
frappe.msgprint({
title: __('Success'),
message: __('Opening Stock Created Successfully: <a href="/app/stock-reconciliation/{0}">{1}</a>',
[r.message, r.message]),
indicator: 'green'
});
frm.reload_doc();
}
}
});
}
});

dialog.show();
});
});

}
});
7 changes: 4 additions & 3 deletions aumms/aumms/doctype/aumms_item/aumms_item.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
"fieldname": "item_type",
"fieldtype": "Link",
"label": "Item Type",
"options": "Item Type"
"options": "Item Type",
"reqd": 1
},
{
"default": "0",
Expand Down Expand Up @@ -132,7 +133,7 @@
},
{
"default": "0",
"fetch_from": "item_group.is_purity_item",
"fetch_from": "item_type.is_purity_item",
"fieldname": "is_purity_item",
"fieldtype": "Check",
"hidden": 1,
Expand Down Expand Up @@ -368,7 +369,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-03-28 09:47:38.898756",
"modified": "2024-11-05 12:06:59.188117",
"modified_by": "Administrator",
"module": "AuMMS",
"name": "AuMMS Item",
Expand Down
Loading
Loading