feat: Return tracking in PR/DN

This commit is contained in:
marination 2020-07-31 15:54:05 +05:30
parent 01e0d50eba
commit 66069df020
7 changed files with 81 additions and 29 deletions

View File

@ -1084,7 +1084,7 @@
"idx": 105,
"is_submittable": 1,
"links": [],
"modified": "2020-07-18 05:09:33.800633",
"modified": "2020-07-31 14:39:44.599294",
"modified_by": "Administrator",
"module": "Buying",
"name": "Purchase Order",
@ -1135,5 +1135,5 @@
"sort_field": "modified",
"sort_order": "DESC",
"timeline_field": "supplier",
"title_field": "title"
"title_field": "supplier"
}

View File

@ -207,6 +207,7 @@ def make_return_doc(doctype, source_name, target_doc=None):
from frappe.model.mapper import get_mapped_doc
company = frappe.db.get_value("Delivery Note", source_name, "company")
default_warehouse_for_sales_return = frappe.db.get_value("Company", company, "default_warehouse_for_sales_return")
def set_missing_values(source, target):
doc = frappe.get_doc(target)
doc.is_return = 1

View File

@ -65,6 +65,7 @@ status_map = {
"Purchase Receipt": [
["Draft", None],
["To Bill", "eval:self.per_billed < 100 and self.docstatus == 1"],
["Return Issued", "eval:self.per_returned == 100 and self.docstatus == 1"],
["Completed", "eval:self.per_billed == 100 and self.docstatus == 1"],
["Cancelled", "eval:self.docstatus==2"],
["Closed", "eval:self.status=='Closed'"],
@ -232,7 +233,7 @@ class StatusUpdater(Document):
self._update_children(args, update_modified)
if "percent_join_field" in args:
if "percent_join_field" in args or "percent_join_field_parent" in args:
self._update_percent_field_in_targets(args, update_modified)
def _update_children(self, args, update_modified):
@ -272,13 +273,19 @@ class StatusUpdater(Document):
def _update_percent_field_in_targets(self, args, update_modified=True):
"""Update percent field in parent transaction"""
distinct_transactions = set([d.get(args['percent_join_field'])
for d in self.get_all_children(args['source_dt'])])
if args.get('percent_join_field_parent'):
# if reference to target doc where % is to be updated, is
# in source doc's parent form, consider percent_join_field_parent
args['name'] = self.get(args['percent_join_field_parent'])
self._update_percent_field(args, update_modified)
else:
distinct_transactions = set([d.get(args['percent_join_field'])
for d in self.get_all_children(args['source_dt'])])
for name in distinct_transactions:
if name:
args['name'] = name
self._update_percent_field(args, update_modified)
for name in distinct_transactions:
if name:
args['name'] = name
self._update_percent_field(args, update_modified)
def _update_percent_field(self, args, update_modified=True):
"""Update percent field in parent transaction"""

View File

@ -1,7 +1,6 @@
{
"actions": [],
"allow_import": 1,
"allow_workflow": 1,
"autoname": "naming_series:",
"creation": "2013-05-21 16:16:39",
"doctype": "DocType",
@ -111,6 +110,7 @@
"range",
"column_break4",
"per_billed",
"per_returned",
"is_internal_supplier",
"inter_company_reference",
"subscription_detail",
@ -1104,13 +1104,23 @@
"fieldtype": "Small Text",
"label": "Billing Address",
"read_only": 1
},
{
"depends_on": "eval:!doc.__islocal",
"fieldname": "per_returned",
"fieldtype": "Percent",
"in_list_view": 1,
"label": "% Returned",
"no_copy": 1,
"print_hide": 1,
"read_only": 1
}
],
"icon": "fa fa-truck",
"idx": 261,
"is_submittable": 1,
"links": [],
"modified": "2020-07-18 05:19:12.148115",
"modified": "2020-07-31 15:16:26.811384",
"modified_by": "Administrator",
"module": "Stock",
"name": "Purchase Receipt",

View File

@ -55,20 +55,33 @@ class PurchaseReceipt(BuyingController):
'percent_join_field': 'material_request'
}]
if cint(self.is_return):
self.status_updater.append({
'source_dt': 'Purchase Receipt Item',
'target_dt': 'Purchase Order Item',
'join_field': 'purchase_order_item',
'target_field': 'returned_qty',
'source_field': '-1 * qty',
'second_source_dt': 'Purchase Invoice Item',
'second_source_field': '-1 * qty',
'second_join_field': 'po_detail',
'extra_cond': """ and exists (select name from `tabPurchase Receipt`
where name=`tabPurchase Receipt Item`.parent and is_return=1)""",
'second_source_extra_cond': """ and exists (select name from `tabPurchase Invoice`
where name=`tabPurchase Invoice Item`.parent and is_return=1 and update_stock=1)"""
})
self.status_updater.extend([
{
'source_dt': 'Purchase Receipt Item',
'target_dt': 'Purchase Order Item',
'join_field': 'purchase_order_item',
'target_field': 'returned_qty',
'source_field': '-1 * qty',
'second_source_dt': 'Purchase Invoice Item',
'second_source_field': '-1 * qty',
'second_join_field': 'po_detail',
'extra_cond': """ and exists (select name from `tabPurchase Receipt`
where name=`tabPurchase Receipt Item`.parent and is_return=1)""",
'second_source_extra_cond': """ and exists (select name from `tabPurchase Invoice`
where name=`tabPurchase Invoice Item`.parent and is_return=1 and update_stock=1)"""
},
{
'source_dt': 'Purchase Receipt Item',
'target_dt': 'Purchase Receipt Item',
'join_field': 'purchase_receipt_item',
'target_field': 'returned_qty',
'target_parent_dt': 'Purchase Receipt',
'target_parent_field': 'per_returned',
'target_ref_field': 'stock_qty',
'source_field': '-1 * stock_qty',
'percent_join_field_parent': 'return_against'
}
])
def validate(self):
self.validate_posting_time()
@ -470,7 +483,7 @@ class PurchaseReceipt(BuyingController):
frappe.db.set_value("Asset", asset.name, "purchase_receipt_amount", flt(valuation_rate))
def update_status(self, status):
self.set_status(update=True, status = status)
self.set_status(update=True, status=status)
self.notify_update()
clear_doctype_notifications(self)

View File

@ -6,6 +6,8 @@ frappe.listview_settings['Purchase Receipt'] = {
return [__("Return"), "darkgrey", "is_return,=,Yes"];
} else if (doc.status === "Closed") {
return [__("Closed"), "green", "status,=,Closed"];
} else if (flt(doc.per_returned, 2) == 100) {
return [__("Return Issued"), "grey", "per_returned,=,100"];
} else if (flt(doc.grand_total) !== 0 && flt(doc.per_billed, 2) < 100) {
return [__("To Bill"), "orange", "per_billed,<,100"];
} else if (flt(doc.grand_total) === 0 || flt(doc.per_billed, 2) == 100) {

View File

@ -28,9 +28,12 @@
"uom",
"stock_uom",
"conversion_factor",
"stock_qty",
"retain_sample",
"sample_quantity",
"tracking_section",
"stock_qty",
"col_break_tracking_section",
"returned_qty",
"rate_and_amount",
"price_list_rate",
"discount_percentage",
@ -526,7 +529,7 @@
{
"fieldname": "stock_qty",
"fieldtype": "Float",
"label": "Accepted Qty as per Stock UOM",
"label": "Accepted Qty in Stock UOM",
"oldfieldname": "stock_qty",
"oldfieldtype": "Currency",
"print_hide": 1,
@ -834,12 +837,28 @@
"collapsible": 1,
"fieldname": "image_column",
"fieldtype": "Column Break"
},
{
"fieldname": "tracking_section",
"fieldtype": "Section Break"
},
{
"fieldname": "col_break_tracking_section",
"fieldtype": "Column Break"
},
{
"depends_on": "returned_qty",
"fieldname": "returned_qty",
"fieldtype": "Float",
"label": "Returned Qty in Stock UOM",
"print_hide": 1,
"read_only": 1
}
],
"idx": 1,
"istable": 1,
"links": [],
"modified": "2020-04-28 19:01:21.154963",
"modified": "2020-07-30 21:02:17.912628",
"modified_by": "Administrator",
"module": "Stock",
"name": "Purchase Receipt Item",