Skip to content

Commit

Permalink
Merge pull request #136 from efeone/dev_customer_advance
Browse files Browse the repository at this point in the history
feat: Customer Advances
  • Loading branch information
muhammadmp authored Aug 22, 2023
2 parents df3843f + 1e8f7c1 commit ad92a9e
Show file tree
Hide file tree
Showing 8 changed files with 408 additions and 33 deletions.
Empty file.
88 changes: 88 additions & 0 deletions aumms/aumms/doctype/customer_advances/customer_advances.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2023-08-09 11:15:15.314229",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"reference",
"posting_date",
"purity",
"board_rate",
"column_break_vvybt",
"amount",
"item_type",
"stock_uom",
"qty_obtained"
],
"fields": [
{
"fieldname": "posting_date",
"fieldtype": "Date",
"in_list_view": 1,
"label": "Posting Date"
},
{
"fieldname": "item_type",
"fieldtype": "Link",
"label": "Item Type",
"options": "Item Type"
},
{
"fieldname": "purity",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Purity",
"options": "Purity"
},
{
"fieldname": "amount",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Amount"
},
{
"fieldname": "board_rate",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Board Rate"
},
{
"fieldname": "stock_uom",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Stock UOM",
"options": "UOM"
},
{
"fieldname": "column_break_vvybt",
"fieldtype": "Column Break"
},
{
"default": "0",
"fieldname": "qty_obtained",
"fieldtype": "Float",
"label": "Qty Obtained"
},
{
"fieldname": "reference",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Reference",
"options": "Payment Entry"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-08-14 13:23:50.948546",
"modified_by": "Administrator",
"module": "AuMMS",
"name": "Customer Advances",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
8 changes: 8 additions & 0 deletions aumms/aumms/doctype/customer_advances/customer_advances.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2023, efeone and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document

class CustomerAdvances(Document):
pass
65 changes: 62 additions & 3 deletions aumms/aumms/doctype/jewellery_invoice/jewellery_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ frappe.ui.form.on('Jewellery Invoice', {
transaction_date: function(frm) {
if (frm.doc.transaction_date ) {
frm.doc.items.forEach((child) => {
set_item_details(child)
set_item_details(frm, child);
});
}
},
Expand Down Expand Up @@ -86,11 +86,16 @@ frappe.ui.form.on('Old Jewellery Item', {
},
qty: function(frm, cdt, cdn){
let d = locals[cdt][cdn];
let total_old_gold_weight;
if (d.qty){
frappe.model.set_value(cdt, cdn, 'amount', d.qty * d.rate);
frm.refresh_field('old_jewellery_items');
if(frm.doc.total_old_gold_weight){
total_old_gold_weight = frm.doc.total_old_gold_weight
}
total_old_gold_weight = total_old_gold_weight + d.qty;
frm.set_value('total_old_gold_weight', total_old_gold_weight);
}
set_net_weight_and_amount(frm);
},
rate: function(frm, cdt, cdn){
let d = locals[cdt][cdn];
Expand Down Expand Up @@ -155,12 +160,18 @@ frappe.ui.form.on('Jewellery Invoice Item', {
},
qty: function(frm, cdt, cdn){
let d = locals[cdt][cdn];
let total_gold_weight;
if (d.qty){
//set amount_with_out_making_charge while changing qty
frappe.model.set_value(d.doctype, d.name, 'amount_with_out_making_charge', d.qty * d.board_rate);
//set amount with rate * qty
frappe.model.set_value(d.doctype, d.name, 'amount', d.qty * d.rate);
frm.refresh_field('items');
if(frm.doc.total_gold_weight){
total_gold_weight = frm.doc.total_gold_weight
}
total_gold_weight = total_gold_weight + d.qty;
frm.set_value('total_gold_weight', total_gold_weight);
}
},
rate: function(frm, cdt, cdn){
Expand All @@ -172,6 +183,7 @@ frappe.ui.form.on('Jewellery Invoice Item', {
}
},
amount: function(frm, cdt, cdn) {
set_net_weight_and_amount(frm);
set_totals(frm);
},
making_charge_percentage: function(frm, cdt, cdn){
Expand Down Expand Up @@ -244,7 +256,7 @@ frappe.ui.form.on('Jewellery Invoice Item', {



let set_item_details = function(child) {
let set_item_details = function(frm, child) {
//function to get item get_item_details
if(child.item_type){
frappe.call({
Expand Down Expand Up @@ -414,6 +426,13 @@ let create_custom_buttons = function(frm){
});;
}, 'Create');
}

if(frm.doc.sales_order && !frm.doc.sales_invoice){
frm.add_custom_button('Get Customer Advances', () => {
//To get customer advances
get_customer_advances(frm);
});
}
}

let make_payment = function(frm){
Expand Down Expand Up @@ -502,3 +521,43 @@ let remove_previous_links = function(frm){
frm.refresh_fields();
}
}

let get_customer_advances= function(frm){
frm.doc.items.forEach((child) => {
frappe.call('aumms.aumms.utils.get_advances_payments_against_so_in_gold', {
sales_order: frm.doc.sales_order,
item_type: child.item_type,
purity: child.purity,
stock_uom: child.stock_uom
}).then(r => {
if(r.message){
frm.clear_table('customer_advances');
let total_advance_received = 0;
let total_qty_obtained = 0;
let purity = '';
let uom = '';
r.message.forEach((advance) => {
frm.add_child('customer_advances', {
'reference': advance.payment_entry,
'posting_date': advance.posting_date,
'item_type': advance.item_type,
'purity': advance.purity,
'amount': advance.amount,
'board_rate': advance.board_rate,
'stock_uom': advance.stock_uom,
'qty_obtained': advance.qty_obtained
});
purity = advance.purity;
uom = advance.stock_uom;
total_advance_received = total_advance_received + (advance.amount);
total_qty_obtained = total_qty_obtained + (advance.qty_obtained);
});
frm.set_value('total_advance_received', total_advance_received);
frm.set_value('total_qty_obtained', total_qty_obtained);
frm.set_value('uom', uom);
frm.set_value('purity', purity);
frm.save_or_update();
}
});
});
}
76 changes: 68 additions & 8 deletions aumms/aumms/doctype/jewellery_invoice/jewellery_invoice.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@
"paid_amount",
"outstanding_amount",
"in_words",
"more_information_section",
"advances_tab",
"customer_advances",
"section_break_y6lif",
"total_advance_received",
"total_qty_obtained",
"column_break_yqyhw",
"purity",
"uom",
"more_tab",
"amended_from",
"sales_order",
"sales_invoice",
Expand Down Expand Up @@ -186,12 +194,6 @@
"search_index": 1,
"width": "100px"
},
{
"collapsible": 1,
"fieldname": "more_information_section",
"fieldtype": "Section Break",
"label": "More Information"
},
{
"fieldname": "sales_order",
"fieldtype": "Link",
Expand Down Expand Up @@ -300,12 +302,70 @@
"fieldtype": "Currency",
"label": "Balance Amount",
"read_only": 1
},
{
"fieldname": "advances_tab",
"fieldtype": "Tab Break",
"label": "Advances"
},
{
"allow_on_submit": 1,
"fieldname": "customer_advances",
"fieldtype": "Table",
"label": "Customer Advances",
"options": "Customer Advances",
"read_only": 1
},
{
"fieldname": "more_tab",
"fieldtype": "Tab Break",
"label": "More Information"
},
{
"allow_on_submit": 1,
"default": "0",
"fieldname": "total_advance_received",
"fieldtype": "Currency",
"label": "Total Advance Received",
"read_only": 1
},
{
"allow_on_submit": 1,
"default": "0",
"fieldname": "total_qty_obtained",
"fieldtype": "Float",
"label": "Total Qty Obtained",
"read_only": 1
},
{
"fieldname": "section_break_y6lif",
"fieldtype": "Section Break"
},
{
"fieldname": "column_break_yqyhw",
"fieldtype": "Column Break"
},
{
"allow_on_submit": 1,
"fieldname": "purity",
"fieldtype": "Link",
"label": "Purity",
"options": "Purity",
"read_only": 1
},
{
"allow_on_submit": 1,
"fieldname": "uom",
"fieldtype": "Link",
"label": "UOM",
"options": "UOM",
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2023-08-11 17:47:50.145344",
"modified": "2023-08-14 14:31:43.405802",
"modified_by": "Administrator",
"module": "AuMMS",
"name": "Jewellery Invoice",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"label": "Quantity and Rate"
},
{
"default": "0",
"fieldname": "qty",
"fieldtype": "Float",
"in_list_view": 1,
Expand Down Expand Up @@ -131,7 +132,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-08-11 17:03:12.383289",
"modified": "2023-08-18 10:00:17.481477",
"modified_by": "Administrator",
"module": "AuMMS",
"name": "Old Jewellery Item",
Expand Down
38 changes: 38 additions & 0 deletions aumms/aumms/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,41 @@ def increase_precision():
system_settings_doc.float_precision = 6
system_settings_doc.save()
frappe.db.commit()

@frappe.whitelist()
def get_advances_payments_against_so(sales_order):
''' Method to get advance payments against SO based on date and Board Rate '''
query = '''
SELECT
pe.name as payment_entry,
pe.posting_date as posting_date,
per.allocated_amount as amount
FROM
`tabPayment Entry` as pe,
`tabPayment Entry Reference` as per
WHERE
pe.name = per.parent AND
per.reference_doctype = 'Sales Order' AND
per.reference_name = '{0}'
ORDER BY
pe.posting_date asc
'''.format(sales_order)
advances = frappe.db.sql(query, as_dict = 1)
return advances

@frappe.whitelist()
def get_advances_payments_against_so_in_gold(sales_order, item_type, purity, stock_uom):
''' Method to get cadvance payments against SO in terms of gold '''
advances = get_advances_payments_against_so(sales_order)
for advance in advances:
advance['item_type'] = item_type
advance['purity'] = purity
advance['stock_uom'] = stock_uom
advance['board_rate'] = 0
advance['qty_obtained'] = 0
board_rate = get_board_rate(item_type, purity, stock_uom, advance.get('posting_date'))
if board_rate:
advance['board_rate'] = board_rate
if advance.get('amount'):
advance['qty_obtained'] = float(advance.get('amount'))/float(board_rate)
return advances
Loading

0 comments on commit ad92a9e

Please sign in to comment.