[enhancement] update landed cost on PI via landed cost voucher when update stock is set on PI
This commit is contained in:
parent
130c57b201
commit
fbb342c1ac
@ -2178,6 +2178,112 @@
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "raw_materials_supplied",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Raw Materials Supplied",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"default": "No",
|
||||
"fieldname": "is_subcontracted",
|
||||
"fieldtype": "Select",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Raw Materials Supplied",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "No\nYes",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "supplier_warehouse",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Supplier Warehouse",
|
||||
"length": 0,
|
||||
"no_copy": 1,
|
||||
"options": "Warehouse",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": "50px",
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0,
|
||||
"width": "50px"
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "supplied_items",
|
||||
"fieldtype": "Table",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Supplied Items",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Purchase Receipt Item Supplied",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
@ -2493,6 +2599,33 @@
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"description": "Warehouse where you are maintaining stock of rejected items",
|
||||
"fieldname": "rejected_warehouse",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Rejected Warehouse",
|
||||
"length": 0,
|
||||
"no_copy": 1,
|
||||
"options": "Warehouse",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
@ -2986,4 +3119,4 @@
|
||||
"timeline_field": "supplier",
|
||||
"title_field": "title",
|
||||
"track_seen": 0
|
||||
}
|
||||
}
|
@ -51,14 +51,6 @@ class PurchaseInvoice(BuyingController):
|
||||
if (self.is_paid == 1):
|
||||
self.validate_cash()
|
||||
|
||||
# validate stock items
|
||||
if (self.update_stock == 1):
|
||||
self.validate_purchase_return()
|
||||
self.validate_rejected_warehouse()
|
||||
self.validate_accepted_rejected_qty()
|
||||
pc_obj = frappe.get_doc('Purchase Common')
|
||||
pc_obj.validate_for_items(self)
|
||||
|
||||
self.check_active_purchase_items()
|
||||
self.check_conversion_rate()
|
||||
self.validate_credit_to_acc()
|
||||
@ -279,9 +271,15 @@ class PurchaseInvoice(BuyingController):
|
||||
'source_field': '-1 * qty',
|
||||
# 'percent_join_field': 'prevdoc_docname',
|
||||
# 'overflow_type': 'receipt',
|
||||
'extra_cond': """ and exists (select name from `tabPurchase Invoice` where name=`tabPurchase Invoice Item`.parent and is_return=1)"""
|
||||
'extra_cond': """ and exists (select name from `tabPurchase Invoice`
|
||||
where name=`tabPurchase Invoice Item`.parent and update_stock=1 and is_return=1)"""
|
||||
}
|
||||
])
|
||||
|
||||
def validate_purchase_receipt(self):
|
||||
for item in self.get("items"):
|
||||
if item.purchase_receipt:
|
||||
frappe.throw(_("Stock cannot be updated against Purchase Receipt {0}").format(item.purchase_receipt))
|
||||
|
||||
def on_submit(self):
|
||||
self.check_prev_docstatus()
|
||||
@ -290,7 +288,6 @@ class PurchaseInvoice(BuyingController):
|
||||
frappe.get_doc('Authorization Control').validate_approving_authority(self.doctype,
|
||||
self.company, self.base_grand_total)
|
||||
|
||||
# make purchase receipt
|
||||
if (self.update_stock == 1):
|
||||
# from erpnext.stock.doctype.purchase_receipt.purchase_receipt import update_stock_ledger
|
||||
self.update_stock_ledger()
|
||||
@ -427,9 +424,15 @@ class PurchaseInvoice(BuyingController):
|
||||
for item in self.get("items"):
|
||||
if flt(item.base_net_amount):
|
||||
account_currency = get_account_currency(item.expense_account)
|
||||
|
||||
if auto_accounting_for_stock and self.update_stock:
|
||||
expense_account = warehouse_account[item.warehouse]["name"]
|
||||
else:
|
||||
expense_account = item.expense_account
|
||||
|
||||
gl_entries.append(
|
||||
self.get_gl_dict({
|
||||
"account": item.expense_account if not self.update_stock else warehouse_account[item.warehouse]["name"],
|
||||
"account": expense_account,
|
||||
"against": self.supplier,
|
||||
"debit": item.base_net_amount,
|
||||
"debit_in_account_currency": item.base_net_amount \
|
||||
|
@ -1282,6 +1282,32 @@
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "bom",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "BOM",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "BOM",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
@ -1435,7 +1461,7 @@
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"allow_on_submit": 1,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "valuation_rate",
|
||||
@ -1483,6 +1509,31 @@
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "landed_cost_voucher_amount",
|
||||
"fieldtype": "Currency",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Landed Cost Voucher Amount",
|
||||
"length": 0,
|
||||
"no_copy": 1,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
}
|
||||
],
|
||||
"hide_heading": 0,
|
||||
@ -1494,7 +1545,7 @@
|
||||
"issingle": 0,
|
||||
"istable": 1,
|
||||
"max_attachments": 0,
|
||||
"modified": "2016-03-28 05:05:27.752823",
|
||||
"modified": "2016-04-07 16:38:30.502386",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Purchase Invoice Item",
|
||||
@ -1503,5 +1554,6 @@
|
||||
"read_only": 0,
|
||||
"read_only_onload": 0,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC"
|
||||
"sort_order": "DESC",
|
||||
"track_seen": 0
|
||||
}
|
@ -32,6 +32,23 @@ class BuyingController(StockController):
|
||||
self.set_qty_as_per_stock_uom()
|
||||
self.validate_stock_or_nonstock_items()
|
||||
self.validate_warehouse()
|
||||
|
||||
if self.doctype=="Purchase Invoice" and getattr(self, "update_stock"):
|
||||
self.validate_purchase_receipt()
|
||||
|
||||
if self.doctype=="Purchase Receipt" or (self.doctype=="Purchase Invoice" and getattr(self, "update_stock")):
|
||||
self.validate_purchase_return()
|
||||
self.validate_rejected_warehouse()
|
||||
self.validate_accepted_rejected_qty()
|
||||
|
||||
pc_obj = frappe.get_doc('Purchase Common')
|
||||
pc_obj.validate_for_items(self)
|
||||
|
||||
#sub-contracting
|
||||
self.validate_for_subcontracting()
|
||||
self.create_raw_materials_supplied("supplied_items")
|
||||
self.set_landed_cost_voucher_amount()
|
||||
self.update_valuation_rate("items")
|
||||
|
||||
def set_missing_values(self, for_validate=False):
|
||||
super(BuyingController, self).set_missing_values(for_validate)
|
||||
@ -60,6 +77,13 @@ class BuyingController(StockController):
|
||||
if tax_for_valuation:
|
||||
frappe.throw(_("Tax Category can not be 'Valuation' or 'Valuation and Total' as all items are non-stock items"))
|
||||
|
||||
def set_landed_cost_voucher_amount(self):
|
||||
for d in self.get("items"):
|
||||
lc_voucher_amount = frappe.db.sql("""select sum(applicable_charges)
|
||||
from `tabLanded Cost Item`
|
||||
where docstatus = 1 and purchase_receipt_item = %s""", d.name)
|
||||
d.landed_cost_voucher_amount = lc_voucher_amount[0][0] if lc_voucher_amount else 0.0
|
||||
|
||||
def set_total_in_words(self):
|
||||
from frappe.utils import money_in_words
|
||||
company_currency = get_company_currency(self.company)
|
||||
@ -108,10 +132,10 @@ class BuyingController(StockController):
|
||||
item.conversion_factor = get_conversion_factor(item.item_code, item.uom).get("conversion_factor") or 1.0
|
||||
|
||||
qty_in_stock_uom = flt(item.qty * item.conversion_factor)
|
||||
rm_supp_cost = flt(item.rm_supp_cost) if self.doctype=="Purchase Receipt" else 0.0
|
||||
rm_supp_cost = flt(item.rm_supp_cost) if self.doctype in ["Purchase Receipt", "Purchase Invoice"] else 0.0
|
||||
|
||||
landed_cost_voucher_amount = flt(item.landed_cost_voucher_amount) \
|
||||
if self.doctype == "Purchase Receipt" else 0.0
|
||||
if self.doctype in ["Purchase Receipt", "Purchase Invoice"] else 0.0
|
||||
|
||||
item.valuation_rate = ((item.base_net_amount + item.item_tax_amount + rm_supp_cost
|
||||
+ landed_cost_voucher_amount) / qty_in_stock_uom)
|
||||
@ -123,7 +147,7 @@ class BuyingController(StockController):
|
||||
frappe.throw(_("Please enter 'Is Subcontracted' as Yes or No"))
|
||||
|
||||
if self.is_subcontracted == "Yes":
|
||||
if self.doctype == "Purchase Receipt" and not self.supplier_warehouse:
|
||||
if self.doctype in ["Purchase Receipt", "Purchase Invoice"] and not self.supplier_warehouse:
|
||||
frappe.throw(_("Supplier Warehouse mandatory for sub-contracted Purchase Receipt"))
|
||||
|
||||
for item in self.get("items"):
|
||||
@ -139,7 +163,7 @@ class BuyingController(StockController):
|
||||
if self.is_subcontracted=="Yes":
|
||||
parent_items = []
|
||||
for item in self.get("items"):
|
||||
if self.doctype == "Purchase Receipt":
|
||||
if self.doctype in ["Purchase Receipt", "Purchase Invoice"]:
|
||||
item.rm_supp_cost = 0.0
|
||||
if item.item_code in self.sub_contracted_items:
|
||||
self.update_raw_materials_supplied(item, raw_material_table)
|
||||
@ -149,7 +173,7 @@ class BuyingController(StockController):
|
||||
|
||||
self.cleanup_raw_materials_supplied(parent_items, raw_material_table)
|
||||
|
||||
elif self.doctype == "Purchase Receipt":
|
||||
elif self.doctype in ["Purchase Receipt", "Purchase Invoice"]:
|
||||
for item in self.get("items"):
|
||||
item.rm_supp_cost = 0.0
|
||||
|
||||
@ -179,7 +203,7 @@ class BuyingController(StockController):
|
||||
|
||||
rm.conversion_factor = item.conversion_factor
|
||||
|
||||
if self.doctype == "Purchase Receipt":
|
||||
if self.doctype in ["Purchase Receipt", "Purchase Invoice"]:
|
||||
rm.consumed_qty = required_qty
|
||||
rm.description = bom_item.description
|
||||
if item.batch_no and not rm.batch_no:
|
||||
@ -272,7 +296,9 @@ class BuyingController(StockController):
|
||||
def validate_rejected_warehouse(self):
|
||||
for d in self.get("items"):
|
||||
if flt(d.rejected_qty) and not d.rejected_warehouse:
|
||||
d.rejected_warehouse = self.rejected_warehouse
|
||||
if self.rejected_warehouse:
|
||||
d.rejected_warehouse = self.rejected_warehouse
|
||||
|
||||
if not d.rejected_warehouse:
|
||||
frappe.throw(_("Row #{0}: Rejected Warehouse is mandatory against rejected Item {1}").format(d.idx, d.item_code))
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
"custom": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"document_type": "Document",
|
||||
"fields": [
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
@ -15,6 +16,7 @@
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Item Code",
|
||||
@ -23,6 +25,7 @@
|
||||
"options": "Item",
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
@ -39,6 +42,7 @@
|
||||
"fieldtype": "Text Editor",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Description",
|
||||
@ -48,6 +52,7 @@
|
||||
"oldfieldtype": "Data",
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": "300px",
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
@ -61,18 +66,47 @@
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "purchase_receipt",
|
||||
"fieldtype": "Link",
|
||||
"fieldname": "receipt_document_type",
|
||||
"fieldtype": "Select",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Purchase Receipt",
|
||||
"label": "Receipt Document Type",
|
||||
"length": 0,
|
||||
"no_copy": 1,
|
||||
"options": "Purchase Receipt",
|
||||
"options": "Purchase Invoice\nPurchase Receipt",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "receipt_document",
|
||||
"fieldtype": "Dynamic Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Receipt Document",
|
||||
"length": 0,
|
||||
"no_copy": 1,
|
||||
"options": "receipt_document_type",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
@ -88,12 +122,14 @@
|
||||
"fieldtype": "Column Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
@ -109,6 +145,7 @@
|
||||
"fieldtype": "Float",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Qty",
|
||||
@ -116,6 +153,7 @@
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
@ -131,6 +169,7 @@
|
||||
"fieldtype": "Currency",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Rate",
|
||||
@ -139,6 +178,7 @@
|
||||
"options": "Company:company:default_currency",
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
@ -154,6 +194,7 @@
|
||||
"fieldtype": "Currency",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Amount",
|
||||
@ -164,6 +205,7 @@
|
||||
"options": "Company:company:default_currency",
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
@ -179,6 +221,7 @@
|
||||
"fieldtype": "Currency",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Applicable Charges",
|
||||
@ -187,6 +230,7 @@
|
||||
"options": "Company:company:default_currency",
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
@ -202,6 +246,7 @@
|
||||
"fieldtype": "Data",
|
||||
"hidden": 1,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Purchase Receipt Item",
|
||||
@ -209,6 +254,7 @@
|
||||
"no_copy": 1,
|
||||
"permlevel": 0,
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
@ -226,12 +272,13 @@
|
||||
"issingle": 0,
|
||||
"istable": 1,
|
||||
"max_attachments": 0,
|
||||
"modified": "2015-11-16 06:29:49.057949",
|
||||
"modified": "2016-04-07 16:18:00.859492",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Landed Cost Item",
|
||||
"owner": "wasim@webnotestech.com",
|
||||
"permissions": [],
|
||||
"read_only": 0,
|
||||
"read_only_onload": 0
|
||||
"read_only_onload": 0,
|
||||
"track_seen": 0
|
||||
}
|
@ -6,25 +6,54 @@
|
||||
"custom": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"document_type": "Document",
|
||||
"fields": [
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "purchase_receipt",
|
||||
"fieldtype": "Link",
|
||||
"fieldname": "receipt_document_type",
|
||||
"fieldtype": "Select",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"label": "Receipt Document Type",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "\nPurchase Invoice\nPurchase Receipt",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"fieldname": "receipt_document",
|
||||
"fieldtype": "Dynamic Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Purchase Receipt",
|
||||
"label": "Receipt Document",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"oldfieldname": "purchase_receipt_no",
|
||||
"oldfieldtype": "Link",
|
||||
"options": "Purchase Receipt",
|
||||
"options": "receipt_document_type",
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": "220px",
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
@ -42,6 +71,7 @@
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Supplier",
|
||||
@ -50,6 +80,7 @@
|
||||
"options": "Supplier",
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
@ -65,12 +96,14 @@
|
||||
"fieldtype": "Column Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 0,
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
@ -87,6 +120,7 @@
|
||||
"fieldtype": "Date",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Posting Date",
|
||||
@ -94,6 +128,7 @@
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
@ -109,6 +144,7 @@
|
||||
"fieldtype": "Currency",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_list_view": 1,
|
||||
"label": "Grand Total",
|
||||
@ -116,6 +152,7 @@
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
@ -133,12 +170,13 @@
|
||||
"issingle": 0,
|
||||
"istable": 1,
|
||||
"max_attachments": 0,
|
||||
"modified": "2015-11-16 06:29:49.106523",
|
||||
"modified": "2016-04-07 15:14:56.955036",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Landed Cost Purchase Receipt",
|
||||
"owner": "wasim@webnotestech.com",
|
||||
"permissions": [],
|
||||
"read_only": 0,
|
||||
"read_only_onload": 0
|
||||
"read_only_onload": 0,
|
||||
"track_seen": 0
|
||||
}
|
@ -8,20 +8,28 @@ frappe.require("assets/erpnext/js/controllers/stock_controller.js");
|
||||
erpnext.stock.LandedCostVoucher = erpnext.stock.StockController.extend({
|
||||
setup: function() {
|
||||
var me = this;
|
||||
this.frm.fields_dict.purchase_receipts.grid.get_field('purchase_receipt').get_query =
|
||||
function() {
|
||||
this.frm.fields_dict.purchase_receipts.grid.get_field('receipt_document').get_query =
|
||||
function(doc, cdt ,cdn) {
|
||||
var d = locals[cdt][cdn]
|
||||
|
||||
var filters = [
|
||||
[d.receipt_document_type, 'docstatus', '=', '1'],
|
||||
[d.receipt_document_type, 'company', '=', me.frm.doc.company],
|
||||
]
|
||||
|
||||
if(d.receipt_document_type == "Purchase Invoice") {
|
||||
filters.push(["Purchase Invoice", "update_stock", "=", "1"])
|
||||
}
|
||||
|
||||
if(!me.frm.doc.company) msgprint(__("Please enter company first"));
|
||||
return {
|
||||
filters:[
|
||||
['Purchase Receipt', 'docstatus', '=', '1'],
|
||||
['Purchase Receipt', 'company', '=', me.frm.doc.company],
|
||||
]
|
||||
filters:filters
|
||||
}
|
||||
};
|
||||
|
||||
this.frm.add_fetch("purchase_receipt", "supplier", "supplier");
|
||||
this.frm.add_fetch("purchase_receipt", "posting_date", "posting_date");
|
||||
this.frm.add_fetch("purchase_receipt", "base_grand_total", "grand_total");
|
||||
this.frm.add_fetch("receipt_document", "supplier", "supplier");
|
||||
this.frm.add_fetch("receipt_document", "posting_date", "posting_date");
|
||||
this.frm.add_fetch("receipt_document", "base_grand_total", "grand_total");
|
||||
|
||||
},
|
||||
|
||||
|
@ -14,9 +14,9 @@ class LandedCostVoucher(Document):
|
||||
for pr in self.get("purchase_receipts"):
|
||||
pr_items = frappe.db.sql("""select pr_item.item_code, pr_item.description,
|
||||
pr_item.qty, pr_item.base_rate, pr_item.base_amount, pr_item.name
|
||||
from `tabPurchase Receipt Item` pr_item where parent = %s
|
||||
and exists(select name from tabItem where name = pr_item.item_code and is_stock_item = 1)""",
|
||||
pr.purchase_receipt, as_dict=True)
|
||||
from `tab{doctype} Item` pr_item where parent = %s
|
||||
and exists(select name from tabItem where name = pr_item.item_code and is_stock_item = 1)
|
||||
""".format(doctype=pr.receipt_document_type), pr.receipt_document, as_dict=True)
|
||||
|
||||
for d in pr_items:
|
||||
item = self.append("items")
|
||||
@ -25,13 +25,13 @@ class LandedCostVoucher(Document):
|
||||
item.qty = d.qty
|
||||
item.rate = d.base_rate
|
||||
item.amount = d.base_amount
|
||||
item.purchase_receipt = pr.purchase_receipt
|
||||
item.receipt_document_type = pr.receipt_document_type
|
||||
item.receipt_document = pr.receipt_document
|
||||
item.purchase_receipt_item = d.name
|
||||
|
||||
if self.get("taxes"):
|
||||
self.set_applicable_charges_for_item()
|
||||
|
||||
|
||||
def validate(self):
|
||||
self.check_mandatory()
|
||||
self.validate_purchase_receipts()
|
||||
@ -43,25 +43,26 @@ class LandedCostVoucher(Document):
|
||||
|
||||
def check_mandatory(self):
|
||||
if not self.get("purchase_receipts"):
|
||||
frappe.throw(_("Please enter Purchase Receipts"))
|
||||
frappe.throw(_("Please enter Receipt Document"))
|
||||
|
||||
if not self.get("taxes"):
|
||||
frappe.throw(_("Please enter Taxes and Charges"))
|
||||
|
||||
def validate_purchase_receipts(self):
|
||||
purchase_receipts = []
|
||||
receipt_documents = []
|
||||
|
||||
for d in self.get("purchase_receipts"):
|
||||
if frappe.db.get_value("Purchase Receipt", d.purchase_receipt, "docstatus") != 1:
|
||||
frappe.throw(_("Purchase Receipt must be submitted"))
|
||||
if frappe.db.get_value(d.receipt_document_type, d.receipt_document, "docstatus") != 1:
|
||||
frappe.throw(_("Receipt document must be submitted"))
|
||||
else:
|
||||
purchase_receipts.append(d.purchase_receipt)
|
||||
receipt_documents.append(d.receipt_document)
|
||||
|
||||
for item in self.get("items"):
|
||||
if not item.purchase_receipt:
|
||||
if not item.receipt_document:
|
||||
frappe.throw(_("Item must be added using 'Get Items from Purchase Receipts' button"))
|
||||
elif item.purchase_receipt not in purchase_receipts:
|
||||
frappe.throw(_("Item Row {0}: Purchase Receipt {1} does not exist in above 'Purchase Receipts' table")
|
||||
.format(item.idx, item.purchase_receipt))
|
||||
elif item.receipt_document not in receipt_documents:
|
||||
frappe.throw(_("Item Row {idx}: {doctype} {docname} does not exist in above '{doctype}' table")
|
||||
.format(idx=item.idx, doctype=item.receipt_document_type, docname=item.receipt_document))
|
||||
|
||||
def set_total_taxes_and_charges(self):
|
||||
self.total_taxes_and_charges = sum([flt(d.amount) for d in self.get("taxes")])
|
||||
@ -83,36 +84,35 @@ class LandedCostVoucher(Document):
|
||||
self.update_landed_cost()
|
||||
|
||||
def update_landed_cost(self):
|
||||
purchase_receipts = list(set([d.purchase_receipt for d in self.get("items")]))
|
||||
for purchase_receipt in purchase_receipts:
|
||||
pr = frappe.get_doc("Purchase Receipt", purchase_receipt)
|
||||
for d in self.get("items"):
|
||||
doc = frappe.get_doc(d.receipt_document_type, d.receipt_document)
|
||||
|
||||
# set landed cost voucher amount in pr item
|
||||
pr.set_landed_cost_voucher_amount()
|
||||
doc.set_landed_cost_voucher_amount()
|
||||
|
||||
# set valuation amount in pr item
|
||||
pr.update_valuation_rate("items")
|
||||
doc.update_valuation_rate("items")
|
||||
|
||||
# save will update landed_cost_voucher_amount and voucher_amount in PR,
|
||||
# as those fields are allowed to edit after submit
|
||||
pr.save()
|
||||
doc.save()
|
||||
|
||||
# update latest valuation rate in serial no
|
||||
self.update_rate_in_serial_no(pr)
|
||||
self.update_rate_in_serial_no(doc)
|
||||
|
||||
# update stock & gl entries for cancelled state of PR
|
||||
pr.docstatus = 2
|
||||
pr.update_stock_ledger(allow_negative_stock=True, via_landed_cost_voucher=True)
|
||||
pr.make_gl_entries_on_cancel()
|
||||
doc.docstatus = 2
|
||||
doc.update_stock_ledger(allow_negative_stock=True, via_landed_cost_voucher=True)
|
||||
doc.make_gl_entries_on_cancel()
|
||||
|
||||
|
||||
# update stock & gl entries for submit state of PR
|
||||
pr.docstatus = 1
|
||||
pr.update_stock_ledger(via_landed_cost_voucher=True)
|
||||
pr.make_gl_entries()
|
||||
doc.docstatus = 1
|
||||
doc.update_stock_ledger(via_landed_cost_voucher=True)
|
||||
doc.make_gl_entries()
|
||||
|
||||
def update_rate_in_serial_no(self, purchase_receipt):
|
||||
for item in purchase_receipt.get("items"):
|
||||
def update_rate_in_serial_no(self, receipt_document):
|
||||
for item in receipt_document.get("items"):
|
||||
if item.serial_no:
|
||||
serial_nos = get_serial_nos(item.serial_no)
|
||||
if serial_nos:
|
||||
|
@ -52,31 +52,13 @@ class PurchaseReceipt(BuyingController):
|
||||
self.set_status()
|
||||
self.po_required()
|
||||
self.validate_with_previous_doc()
|
||||
self.validate_purchase_return()
|
||||
self.validate_rejected_warehouse()
|
||||
self.validate_accepted_rejected_qty()
|
||||
self.validate_inspection()
|
||||
self.validate_uom_is_integer("uom", ["qty", "received_qty"])
|
||||
self.validate_uom_is_integer("stock_uom", "stock_qty")
|
||||
|
||||
pc_obj = frappe.get_doc('Purchase Common')
|
||||
pc_obj.validate_for_items(self)
|
||||
self.check_for_closed_status(pc_obj)
|
||||
|
||||
# sub-contracting
|
||||
self.validate_for_subcontracting()
|
||||
self.create_raw_materials_supplied("supplied_items")
|
||||
self.set_landed_cost_voucher_amount()
|
||||
self.update_valuation_rate("items")
|
||||
|
||||
|
||||
def set_landed_cost_voucher_amount(self):
|
||||
for d in self.get("items"):
|
||||
lc_voucher_amount = frappe.db.sql("""select sum(applicable_charges)
|
||||
from `tabLanded Cost Item`
|
||||
where docstatus = 1 and purchase_receipt_item = %s""", d.name)
|
||||
d.landed_cost_voucher_amount = lc_voucher_amount[0][0] if lc_voucher_amount else 0.0
|
||||
|
||||
def validate_with_previous_doc(self):
|
||||
super(PurchaseReceipt, self).validate_with_previous_doc({
|
||||
"Purchase Order": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user