-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #217 from efeone/purchase_tool_submit
feat:Create Item, Purchase Receipt and Metal Ledger while Submitting the Purchase Tool
- Loading branch information
Showing
2 changed files
with
85 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,62 @@ | ||
# Copyright (c) 2024, efeone and contributors | ||
# For license information, please see license.txt | ||
|
||
# import frappe | ||
import frappe | ||
from frappe.model.document import Document | ||
|
||
from frappe.model.naming import make_autoname | ||
from frappe.model.mapper import get_mapped_doc | ||
|
||
class PurchaseTool(Document): | ||
pass | ||
|
||
def before_submit(self): | ||
self.create_item() | ||
|
||
def on_submit(self): | ||
self.create_purchase_receipt() | ||
|
||
def create_item(self): | ||
for item_detail in self.get("item_details"): | ||
aumms_item = frappe.new_doc('AuMMS Item') | ||
aumms_item.item_code = item_detail.item_code | ||
aumms_item.item_name = item_detail.item_code | ||
aumms_item.purity = item_detail.purity | ||
aumms_item.item_group = self.item_group | ||
aumms_item.item_type = self.item_type | ||
aumms_item.weight_per_unit = item_detail.net_weight | ||
aumms_item.weight_uom = item_detail.uom | ||
aumms_item.has_stone = self.has_stone | ||
# If has_stone is checked, fetch stone details from item_detail | ||
if self.has_stone: | ||
aumms_item.append('stone_details', { | ||
'stone_weight': item_detail.stone_weight, | ||
'stone_charge': item_detail.stone_charge, | ||
'item_name': self.stone, | ||
'item_type': self.stone, | ||
}) | ||
frappe.msgprint('AuMMS Item Created.') | ||
aumms_item.insert(ignore_permissions=True) | ||
|
||
def create_purchase_receipt(self): | ||
purchase_receipt = frappe.new_doc('Purchase Receipt') | ||
purchase_receipt.supplier = self.supplier, | ||
purchase_receipt.keep_metal_ledger = 1 | ||
|
||
for item_detail in self.get("item_details"): | ||
# Fetch details from AuMMS Item's item_details | ||
aumms_item = frappe.get_doc('AuMMS Item', item_detail.item_code) | ||
|
||
purchase_receipt.append('items', { | ||
'item_code': aumms_item.item_code, | ||
'item_name': aumms_item.item_name, | ||
'qty': item_detail.net_weight, | ||
'uom': item_detail.uom, | ||
'stock_uom': aumms_item.weight_uom, | ||
'conversion_factor': aumms_item.weight_per_unit / item_detail.net_weight, | ||
'base_rate': self.board_rate, | ||
}) | ||
|
||
# Save and submit the Purchase Receipt | ||
purchase_receipt.insert(ignore_permissions=True) | ||
purchase_receipt.save(ignore_permissions=True) | ||
purchase_receipt.submit() | ||
|
||
frappe.msgprint('Purchase Receipt created and submitted successfully.') |