mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-08 15:42:52 +00:00
Merge branch 'develop' of https://github.com/frappe/erpnext into pending_tds_vouchers
This commit is contained in:
@@ -176,7 +176,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"collapsible": 1,
|
"collapsible": 1,
|
||||||
"depends_on": "eval:doc.apply_on != 'Transaction'",
|
"depends_on": "eval:doc.apply_on != 'Transaction' && !doc.mixed_conditions",
|
||||||
"fieldname": "section_break_18",
|
"fieldname": "section_break_18",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Discount on Other Item"
|
"label": "Discount on Other Item"
|
||||||
@@ -297,12 +297,12 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "min_qty",
|
"fieldname": "min_qty",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
"label": "Min Qty"
|
"label": "Min Qty (As Per Stock UOM)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "max_qty",
|
"fieldname": "max_qty",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
"label": "Max Qty"
|
"label": "Max Qty (As Per Stock UOM)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "column_break_21",
|
"fieldname": "column_break_21",
|
||||||
@@ -481,7 +481,7 @@
|
|||||||
"description": "System will notify to increase or decrease quantity or amount ",
|
"description": "System will notify to increase or decrease quantity or amount ",
|
||||||
"fieldname": "threshold_percentage",
|
"fieldname": "threshold_percentage",
|
||||||
"fieldtype": "Percent",
|
"fieldtype": "Percent",
|
||||||
"label": "Threshold for Suggestion"
|
"label": "Threshold for Suggestion (In Percentage)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "Higher the number, higher the priority",
|
"description": "Higher the number, higher the priority",
|
||||||
@@ -583,10 +583,11 @@
|
|||||||
"icon": "fa fa-gift",
|
"icon": "fa fa-gift",
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-08-06 15:10:04.219321",
|
"modified": "2022-09-16 16:00:38.356266",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Pricing Rule",
|
"name": "Pricing Rule",
|
||||||
|
"naming_rule": "By \"Naming Series\" field",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
{
|
{
|
||||||
@@ -642,5 +643,6 @@
|
|||||||
"show_name_in_global_search": 1,
|
"show_name_in_global_search": 1,
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
|
"states": [],
|
||||||
"title_field": "title"
|
"title_field": "title"
|
||||||
}
|
}
|
||||||
@@ -324,7 +324,7 @@ def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=Fa
|
|||||||
|
|
||||||
if isinstance(pricing_rule, str):
|
if isinstance(pricing_rule, str):
|
||||||
pricing_rule = frappe.get_cached_doc("Pricing Rule", pricing_rule)
|
pricing_rule = frappe.get_cached_doc("Pricing Rule", pricing_rule)
|
||||||
pricing_rule.apply_rule_on_other_items = get_pricing_rule_items(pricing_rule)
|
pricing_rule.apply_rule_on_other_items = get_pricing_rule_items(pricing_rule) or []
|
||||||
|
|
||||||
if pricing_rule.get("suggestion"):
|
if pricing_rule.get("suggestion"):
|
||||||
continue
|
continue
|
||||||
@@ -337,7 +337,6 @@ def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=Fa
|
|||||||
if pricing_rule.mixed_conditions or pricing_rule.apply_rule_on_other:
|
if pricing_rule.mixed_conditions or pricing_rule.apply_rule_on_other:
|
||||||
item_details.update(
|
item_details.update(
|
||||||
{
|
{
|
||||||
"apply_rule_on_other_items": json.dumps(pricing_rule.apply_rule_on_other_items),
|
|
||||||
"price_or_product_discount": pricing_rule.price_or_product_discount,
|
"price_or_product_discount": pricing_rule.price_or_product_discount,
|
||||||
"apply_rule_on": (
|
"apply_rule_on": (
|
||||||
frappe.scrub(pricing_rule.apply_rule_on_other)
|
frappe.scrub(pricing_rule.apply_rule_on_other)
|
||||||
@@ -347,6 +346,9 @@ def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=Fa
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if pricing_rule.apply_rule_on_other_items:
|
||||||
|
item_details["apply_rule_on_other_items"] = json.dumps(pricing_rule.apply_rule_on_other_items)
|
||||||
|
|
||||||
if pricing_rule.coupon_code_based == 1 and args.coupon_code == None:
|
if pricing_rule.coupon_code_based == 1 and args.coupon_code == None:
|
||||||
return item_details
|
return item_details
|
||||||
|
|
||||||
@@ -492,7 +494,7 @@ def remove_pricing_rule_for_item(pricing_rules, item_details, item_code=None, ra
|
|||||||
)
|
)
|
||||||
|
|
||||||
if pricing_rule.get("mixed_conditions") or pricing_rule.get("apply_rule_on_other"):
|
if pricing_rule.get("mixed_conditions") or pricing_rule.get("apply_rule_on_other"):
|
||||||
items = get_pricing_rule_items(pricing_rule)
|
items = get_pricing_rule_items(pricing_rule, other_items=True)
|
||||||
item_details.apply_on = (
|
item_details.apply_on = (
|
||||||
frappe.scrub(pricing_rule.apply_rule_on_other)
|
frappe.scrub(pricing_rule.apply_rule_on_other)
|
||||||
if pricing_rule.apply_rule_on_other
|
if pricing_rule.apply_rule_on_other
|
||||||
|
|||||||
@@ -766,6 +766,68 @@ class TestPricingRule(unittest.TestCase):
|
|||||||
frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule with Min Qty - 1")
|
frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule with Min Qty - 1")
|
||||||
frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule with Min Qty - 2")
|
frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule with Min Qty - 2")
|
||||||
|
|
||||||
|
def test_pricing_rule_for_other_items_cond_with_amount(self):
|
||||||
|
item = make_item("Water Flask New")
|
||||||
|
other_item = make_item("Other Water Flask New")
|
||||||
|
make_item_price(item.name, "_Test Price List", 100)
|
||||||
|
make_item_price(other_item.name, "_Test Price List", 100)
|
||||||
|
|
||||||
|
pricing_rule_record = {
|
||||||
|
"doctype": "Pricing Rule",
|
||||||
|
"title": "_Test Water Flask Rule",
|
||||||
|
"apply_on": "Item Code",
|
||||||
|
"apply_rule_on_other": "Item Code",
|
||||||
|
"price_or_product_discount": "Price",
|
||||||
|
"rate_or_discount": "Discount Percentage",
|
||||||
|
"other_item_code": other_item.name,
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"item_code": item.name,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"selling": 1,
|
||||||
|
"currency": "INR",
|
||||||
|
"min_amt": 200,
|
||||||
|
"discount_percentage": 10,
|
||||||
|
"company": "_Test Company",
|
||||||
|
}
|
||||||
|
rule = frappe.get_doc(pricing_rule_record)
|
||||||
|
rule.insert()
|
||||||
|
|
||||||
|
si = create_sales_invoice(do_not_save=True, item_code=item.name)
|
||||||
|
si.append(
|
||||||
|
"items",
|
||||||
|
{
|
||||||
|
"item_code": other_item.name,
|
||||||
|
"item_name": other_item.item_name,
|
||||||
|
"description": other_item.description,
|
||||||
|
"stock_uom": other_item.stock_uom,
|
||||||
|
"uom": other_item.stock_uom,
|
||||||
|
"cost_center": si.items[0].cost_center,
|
||||||
|
"expense_account": si.items[0].expense_account,
|
||||||
|
"warehouse": si.items[0].warehouse,
|
||||||
|
"conversion_factor": 1,
|
||||||
|
"qty": 1,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
si.selling_price_list = "_Test Price List"
|
||||||
|
si.save()
|
||||||
|
|
||||||
|
self.assertEqual(si.items[0].discount_percentage, 0)
|
||||||
|
self.assertEqual(si.items[1].discount_percentage, 0)
|
||||||
|
|
||||||
|
si.items[0].qty = 2
|
||||||
|
si.save()
|
||||||
|
|
||||||
|
self.assertEqual(si.items[0].discount_percentage, 0)
|
||||||
|
self.assertEqual(si.items[0].stock_qty, 2)
|
||||||
|
self.assertEqual(si.items[0].amount, 200)
|
||||||
|
self.assertEqual(si.items[0].price_list_rate, 100)
|
||||||
|
self.assertEqual(si.items[1].discount_percentage, 10)
|
||||||
|
|
||||||
|
si.delete()
|
||||||
|
rule.delete()
|
||||||
|
|
||||||
|
|
||||||
test_dependencies = ["Campaign"]
|
test_dependencies = ["Campaign"]
|
||||||
|
|
||||||
|
|||||||
@@ -252,12 +252,6 @@ def filter_pricing_rules(args, pricing_rules, doc=None):
|
|||||||
stock_qty = flt(args.get("stock_qty"))
|
stock_qty = flt(args.get("stock_qty"))
|
||||||
amount = flt(args.get("price_list_rate")) * flt(args.get("qty"))
|
amount = flt(args.get("price_list_rate")) * flt(args.get("qty"))
|
||||||
|
|
||||||
if pricing_rules[0].apply_rule_on_other:
|
|
||||||
field = frappe.scrub(pricing_rules[0].apply_rule_on_other)
|
|
||||||
|
|
||||||
if field and pricing_rules[0].get("other_" + field) != args.get(field):
|
|
||||||
return
|
|
||||||
|
|
||||||
pr_doc = frappe.get_cached_doc("Pricing Rule", pricing_rules[0].name)
|
pr_doc = frappe.get_cached_doc("Pricing Rule", pricing_rules[0].name)
|
||||||
|
|
||||||
if pricing_rules[0].mixed_conditions and doc:
|
if pricing_rules[0].mixed_conditions and doc:
|
||||||
@@ -274,7 +268,7 @@ def filter_pricing_rules(args, pricing_rules, doc=None):
|
|||||||
amount += data[1]
|
amount += data[1]
|
||||||
|
|
||||||
if pricing_rules[0].apply_rule_on_other and not pricing_rules[0].mixed_conditions and doc:
|
if pricing_rules[0].apply_rule_on_other and not pricing_rules[0].mixed_conditions and doc:
|
||||||
pricing_rules = get_qty_and_rate_for_other_item(doc, pr_doc, pricing_rules) or []
|
pricing_rules = get_qty_and_rate_for_other_item(doc, pr_doc, pricing_rules, args) or []
|
||||||
else:
|
else:
|
||||||
pricing_rules = filter_pricing_rules_for_qty_amount(stock_qty, amount, pricing_rules, args)
|
pricing_rules = filter_pricing_rules_for_qty_amount(stock_qty, amount, pricing_rules, args)
|
||||||
|
|
||||||
@@ -352,16 +346,14 @@ def validate_quantity_and_amount_for_suggestion(args, qty, amount, item_code, tr
|
|||||||
if fieldname:
|
if fieldname:
|
||||||
msg = _(
|
msg = _(
|
||||||
"If you {0} {1} quantities of the item {2}, the scheme {3} will be applied on the item."
|
"If you {0} {1} quantities of the item {2}, the scheme {3} will be applied on the item."
|
||||||
).format(
|
).format(type_of_transaction, args.get(fieldname), bold(item_code), bold(args.title))
|
||||||
type_of_transaction, args.get(fieldname), bold(item_code), bold(args.rule_description)
|
|
||||||
)
|
|
||||||
|
|
||||||
if fieldname in ["min_amt", "max_amt"]:
|
if fieldname in ["min_amt", "max_amt"]:
|
||||||
msg = _("If you {0} {1} worth item {2}, the scheme {3} will be applied on the item.").format(
|
msg = _("If you {0} {1} worth item {2}, the scheme {3} will be applied on the item.").format(
|
||||||
type_of_transaction,
|
type_of_transaction,
|
||||||
fmt_money(args.get(fieldname), currency=args.get("currency")),
|
fmt_money(args.get(fieldname), currency=args.get("currency")),
|
||||||
bold(item_code),
|
bold(item_code),
|
||||||
bold(args.rule_description),
|
bold(args.title),
|
||||||
)
|
)
|
||||||
|
|
||||||
frappe.msgprint(msg)
|
frappe.msgprint(msg)
|
||||||
@@ -454,17 +446,29 @@ def get_qty_and_rate_for_mixed_conditions(doc, pr_doc, args):
|
|||||||
return sum_qty, sum_amt, items
|
return sum_qty, sum_amt, items
|
||||||
|
|
||||||
|
|
||||||
def get_qty_and_rate_for_other_item(doc, pr_doc, pricing_rules):
|
def get_qty_and_rate_for_other_item(doc, pr_doc, pricing_rules, row_item):
|
||||||
items = get_pricing_rule_items(pr_doc)
|
other_items = get_pricing_rule_items(pr_doc, other_items=True)
|
||||||
|
pricing_rule_apply_on = apply_on_table.get(pr_doc.get("apply_on"))
|
||||||
|
apply_on = frappe.scrub(pr_doc.get("apply_on"))
|
||||||
|
|
||||||
|
items = []
|
||||||
|
for d in pr_doc.get(pricing_rule_apply_on):
|
||||||
|
if apply_on == "item_group":
|
||||||
|
items.extend(get_child_item_groups(d.get(apply_on)))
|
||||||
|
else:
|
||||||
|
items.append(d.get(apply_on))
|
||||||
|
|
||||||
for row in doc.items:
|
for row in doc.items:
|
||||||
if row.get(frappe.scrub(pr_doc.apply_rule_on_other)) in items:
|
if row.get(apply_on) in items:
|
||||||
pricing_rules = filter_pricing_rules_for_qty_amount(
|
if not row.get("qty"):
|
||||||
row.get("stock_qty"), row.get("amount"), pricing_rules, row
|
continue
|
||||||
)
|
|
||||||
|
stock_qty = row.get("qty") * (row.get("conversion_factor") or 1.0)
|
||||||
|
amount = stock_qty * (row.get("price_list_rate") or row.get("rate"))
|
||||||
|
pricing_rules = filter_pricing_rules_for_qty_amount(stock_qty, amount, pricing_rules, row)
|
||||||
|
|
||||||
if pricing_rules and pricing_rules[0]:
|
if pricing_rules and pricing_rules[0]:
|
||||||
pricing_rules[0].apply_rule_on_other_items = items
|
pricing_rules[0].apply_rule_on_other_items = other_items
|
||||||
return pricing_rules
|
return pricing_rules
|
||||||
|
|
||||||
|
|
||||||
@@ -658,21 +662,21 @@ def apply_pricing_rule_for_free_items(doc, pricing_rule_args, set_missing_values
|
|||||||
doc.append("items", args)
|
doc.append("items", args)
|
||||||
|
|
||||||
|
|
||||||
def get_pricing_rule_items(pr_doc):
|
def get_pricing_rule_items(pr_doc, other_items=False) -> list:
|
||||||
apply_on_data = []
|
apply_on_data = []
|
||||||
apply_on = frappe.scrub(pr_doc.get("apply_on"))
|
apply_on = frappe.scrub(pr_doc.get("apply_on"))
|
||||||
|
|
||||||
pricing_rule_apply_on = apply_on_table.get(pr_doc.get("apply_on"))
|
pricing_rule_apply_on = apply_on_table.get(pr_doc.get("apply_on"))
|
||||||
|
|
||||||
for d in pr_doc.get(pricing_rule_apply_on):
|
if pr_doc.apply_rule_on_other and other_items:
|
||||||
if apply_on == "item_group":
|
|
||||||
apply_on_data.extend(get_child_item_groups(d.get(apply_on)))
|
|
||||||
else:
|
|
||||||
apply_on_data.append(d.get(apply_on))
|
|
||||||
|
|
||||||
if pr_doc.apply_rule_on_other:
|
|
||||||
apply_on = frappe.scrub(pr_doc.apply_rule_on_other)
|
apply_on = frappe.scrub(pr_doc.apply_rule_on_other)
|
||||||
apply_on_data.append(pr_doc.get("other_" + apply_on))
|
apply_on_data.append(pr_doc.get("other_" + apply_on))
|
||||||
|
else:
|
||||||
|
for d in pr_doc.get(pricing_rule_apply_on):
|
||||||
|
if apply_on == "item_group":
|
||||||
|
apply_on_data.extend(get_child_item_groups(d.get(apply_on)))
|
||||||
|
else:
|
||||||
|
apply_on_data.append(d.get(apply_on))
|
||||||
|
|
||||||
return list(set(apply_on_data))
|
return list(set(apply_on_data))
|
||||||
|
|
||||||
|
|||||||
@@ -295,131 +295,12 @@ erpnext.buying.PurchaseOrderController = class PurchaseOrderController extends e
|
|||||||
}
|
}
|
||||||
|
|
||||||
make_stock_entry() {
|
make_stock_entry() {
|
||||||
var items = $.map(cur_frm.doc.items, function(d) { return d.bom ? d.item_code : false; });
|
|
||||||
var me = this;
|
|
||||||
|
|
||||||
if(items.length >= 1){
|
|
||||||
me.raw_material_data = [];
|
|
||||||
me.show_dialog = 1;
|
|
||||||
let title = __('Transfer Material to Supplier');
|
|
||||||
let fields = [
|
|
||||||
{fieldtype:'Section Break', label: __('Raw Materials')},
|
|
||||||
{fieldname: 'sub_con_rm_items', fieldtype: 'Table', label: __('Items'),
|
|
||||||
fields: [
|
|
||||||
{
|
|
||||||
fieldtype:'Data',
|
|
||||||
fieldname:'item_code',
|
|
||||||
label: __('Item'),
|
|
||||||
read_only:1,
|
|
||||||
in_list_view:1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fieldtype:'Data',
|
|
||||||
fieldname:'rm_item_code',
|
|
||||||
label: __('Raw Material'),
|
|
||||||
read_only:1,
|
|
||||||
in_list_view:1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fieldtype:'Float',
|
|
||||||
read_only:1,
|
|
||||||
fieldname:'qty',
|
|
||||||
label: __('Quantity'),
|
|
||||||
read_only:1,
|
|
||||||
in_list_view:1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fieldtype:'Data',
|
|
||||||
read_only:1,
|
|
||||||
fieldname:'warehouse',
|
|
||||||
label: __('Reserve Warehouse'),
|
|
||||||
in_list_view:1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fieldtype:'Float',
|
|
||||||
read_only:1,
|
|
||||||
fieldname:'rate',
|
|
||||||
label: __('Rate'),
|
|
||||||
hidden:1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fieldtype:'Float',
|
|
||||||
read_only:1,
|
|
||||||
fieldname:'amount',
|
|
||||||
label: __('Amount'),
|
|
||||||
hidden:1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fieldtype:'Link',
|
|
||||||
read_only:1,
|
|
||||||
fieldname:'uom',
|
|
||||||
label: __('UOM'),
|
|
||||||
hidden:1
|
|
||||||
}
|
|
||||||
],
|
|
||||||
data: me.raw_material_data,
|
|
||||||
get_data: function() {
|
|
||||||
return me.raw_material_data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
me.dialog = new frappe.ui.Dialog({
|
|
||||||
title: title, fields: fields
|
|
||||||
});
|
|
||||||
|
|
||||||
if (me.frm.doc['supplied_items']) {
|
|
||||||
me.frm.doc['supplied_items'].forEach((item, index) => {
|
|
||||||
if (item.rm_item_code && item.main_item_code && item.required_qty - item.supplied_qty != 0) {
|
|
||||||
me.raw_material_data.push ({
|
|
||||||
'name':item.name,
|
|
||||||
'item_code': item.main_item_code,
|
|
||||||
'rm_item_code': item.rm_item_code,
|
|
||||||
'item_name': item.rm_item_code,
|
|
||||||
'qty': item.required_qty - item.supplied_qty,
|
|
||||||
'warehouse':item.reserve_warehouse,
|
|
||||||
'rate':item.rate,
|
|
||||||
'amount':item.amount,
|
|
||||||
'stock_uom':item.stock_uom
|
|
||||||
});
|
|
||||||
me.dialog.fields_dict.sub_con_rm_items.grid.refresh();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
me.dialog.get_field('sub_con_rm_items').check_all_rows()
|
|
||||||
|
|
||||||
me.dialog.show()
|
|
||||||
this.dialog.set_primary_action(__('Transfer'), function() {
|
|
||||||
me.values = me.dialog.get_values();
|
|
||||||
if(me.values) {
|
|
||||||
me.values.sub_con_rm_items.map((row,i) => {
|
|
||||||
if (!row.item_code || !row.rm_item_code || !row.warehouse || !row.qty || row.qty === 0) {
|
|
||||||
let row_id = i+1;
|
|
||||||
frappe.throw(__("Item Code, warehouse and quantity are required on row {0}", [row_id]));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
me._make_rm_stock_entry(me.dialog.fields_dict.sub_con_rm_items.grid.get_selected_children())
|
|
||||||
me.dialog.hide()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
me.dialog.get_close_btn().on('click', () => {
|
|
||||||
me.dialog.hide();
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
_make_rm_stock_entry(rm_items) {
|
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method:"erpnext.controllers.subcontracting_controller.make_rm_stock_entry",
|
method:"erpnext.controllers.subcontracting_controller.make_rm_stock_entry",
|
||||||
args: {
|
args: {
|
||||||
subcontract_order: cur_frm.doc.name,
|
subcontract_order: cur_frm.doc.name,
|
||||||
rm_items: rm_items,
|
|
||||||
order_doctype: cur_frm.doc.doctype
|
order_doctype: cur_frm.doc.doctype
|
||||||
}
|
},
|
||||||
,
|
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
var doclist = frappe.model.sync(r.message);
|
var doclist = frappe.model.sync(r.message);
|
||||||
frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
|
frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
|
||||||
|
|||||||
@@ -572,6 +572,11 @@ class AccountsController(TransactionBase):
|
|||||||
# if user changed the discount percentage then set user's discount percentage ?
|
# if user changed the discount percentage then set user's discount percentage ?
|
||||||
if pricing_rule_args.get("price_or_product_discount") == "Price":
|
if pricing_rule_args.get("price_or_product_discount") == "Price":
|
||||||
item.set("pricing_rules", pricing_rule_args.get("pricing_rules"))
|
item.set("pricing_rules", pricing_rule_args.get("pricing_rules"))
|
||||||
|
if pricing_rule_args.get("apply_rule_on_other_items"):
|
||||||
|
other_items = json.loads(pricing_rule_args.get("apply_rule_on_other_items"))
|
||||||
|
if other_items and item.item_code not in other_items:
|
||||||
|
return
|
||||||
|
|
||||||
item.set("discount_percentage", pricing_rule_args.get("discount_percentage"))
|
item.set("discount_percentage", pricing_rule_args.get("discount_percentage"))
|
||||||
item.set("discount_amount", pricing_rule_args.get("discount_amount"))
|
item.set("discount_amount", pricing_rule_args.get("discount_amount"))
|
||||||
if pricing_rule_args.get("pricing_rule_for") == "Rate":
|
if pricing_rule_args.get("pricing_rule_for") == "Rate":
|
||||||
|
|||||||
@@ -770,7 +770,7 @@ def get_item_details(items):
|
|||||||
item = frappe.qb.DocType("Item")
|
item = frappe.qb.DocType("Item")
|
||||||
item_list = (
|
item_list = (
|
||||||
frappe.qb.from_(item)
|
frappe.qb.from_(item)
|
||||||
.select(item.item_code, item.description, item.allow_alternative_item)
|
.select(item.item_code, item.item_name, item.description, item.allow_alternative_item)
|
||||||
.where(item.name.isin(items))
|
.where(item.name.isin(items))
|
||||||
.run(as_dict=True)
|
.run(as_dict=True)
|
||||||
)
|
)
|
||||||
@@ -783,68 +783,93 @@ def get_item_details(items):
|
|||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def make_rm_stock_entry(subcontract_order, rm_items, order_doctype="Subcontracting Order"):
|
def make_rm_stock_entry(
|
||||||
rm_items_list = rm_items
|
subcontract_order, rm_items=None, order_doctype="Subcontracting Order", target_doc=None
|
||||||
|
):
|
||||||
if isinstance(rm_items, str):
|
|
||||||
rm_items_list = json.loads(rm_items)
|
|
||||||
elif not rm_items:
|
|
||||||
frappe.throw(_("No Items available for transfer"))
|
|
||||||
|
|
||||||
if rm_items_list:
|
|
||||||
fg_items = list(set(item["item_code"] for item in rm_items_list))
|
|
||||||
else:
|
|
||||||
frappe.throw(_("No Items selected for transfer"))
|
|
||||||
|
|
||||||
if subcontract_order:
|
if subcontract_order:
|
||||||
subcontract_order = frappe.get_doc(order_doctype, subcontract_order)
|
subcontract_order = frappe.get_doc(order_doctype, subcontract_order)
|
||||||
|
|
||||||
if fg_items:
|
if not rm_items:
|
||||||
items = tuple(set(item["rm_item_code"] for item in rm_items_list))
|
if not subcontract_order.supplied_items:
|
||||||
item_wh = get_item_details(items)
|
frappe.throw(_("No item available for transfer."))
|
||||||
|
|
||||||
stock_entry = frappe.new_doc("Stock Entry")
|
rm_items = subcontract_order.supplied_items
|
||||||
stock_entry.purpose = "Send to Subcontractor"
|
|
||||||
if order_doctype == "Purchase Order":
|
|
||||||
stock_entry.purchase_order = subcontract_order.name
|
|
||||||
else:
|
|
||||||
stock_entry.subcontracting_order = subcontract_order.name
|
|
||||||
stock_entry.supplier = subcontract_order.supplier
|
|
||||||
stock_entry.supplier_name = subcontract_order.supplier_name
|
|
||||||
stock_entry.supplier_address = subcontract_order.supplier_address
|
|
||||||
stock_entry.address_display = subcontract_order.address_display
|
|
||||||
stock_entry.company = subcontract_order.company
|
|
||||||
stock_entry.to_warehouse = subcontract_order.supplier_warehouse
|
|
||||||
stock_entry.set_stock_entry_type()
|
|
||||||
|
|
||||||
if order_doctype == "Purchase Order":
|
fg_item_code_list = list(
|
||||||
rm_detail_field = "po_detail"
|
set(item.get("main_item_code") or item.get("item_code") for item in rm_items)
|
||||||
else:
|
)
|
||||||
rm_detail_field = "sco_rm_detail"
|
|
||||||
|
|
||||||
for item_code in fg_items:
|
if fg_item_code_list:
|
||||||
for rm_item_data in rm_items_list:
|
rm_item_code_list = tuple(set(item.get("rm_item_code") for item in rm_items))
|
||||||
if rm_item_data["item_code"] == item_code:
|
item_wh = get_item_details(rm_item_code_list)
|
||||||
rm_item_code = rm_item_data["rm_item_code"]
|
|
||||||
items_dict = {
|
field_no_map, rm_detail_field = "purchase_order", "sco_rm_detail"
|
||||||
rm_item_code: {
|
if order_doctype == "Purchase Order":
|
||||||
rm_detail_field: rm_item_data.get("name"),
|
field_no_map, rm_detail_field = "subcontracting_order", "po_detail"
|
||||||
"item_name": rm_item_data["item_name"],
|
|
||||||
"description": item_wh.get(rm_item_code, {}).get("description", ""),
|
if target_doc and target_doc.get("items"):
|
||||||
"qty": rm_item_data["qty"],
|
target_doc.items = []
|
||||||
"from_warehouse": rm_item_data["warehouse"],
|
|
||||||
"stock_uom": rm_item_data["stock_uom"],
|
stock_entry = get_mapped_doc(
|
||||||
"serial_no": rm_item_data.get("serial_no"),
|
order_doctype,
|
||||||
"batch_no": rm_item_data.get("batch_no"),
|
subcontract_order.name,
|
||||||
"main_item_code": rm_item_data["item_code"],
|
{
|
||||||
"allow_alternative_item": item_wh.get(rm_item_code, {}).get("allow_alternative_item"),
|
order_doctype: {
|
||||||
|
"doctype": "Stock Entry",
|
||||||
|
"field_map": {
|
||||||
|
"to_warehouse": "supplier_warehouse",
|
||||||
|
},
|
||||||
|
"field_no_map": [field_no_map],
|
||||||
|
"validation": {
|
||||||
|
"docstatus": ["=", 1],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
target_doc,
|
||||||
|
ignore_child_tables=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
stock_entry.purpose = "Send to Subcontractor"
|
||||||
|
|
||||||
|
if order_doctype == "Purchase Order":
|
||||||
|
stock_entry.purchase_order = subcontract_order.name
|
||||||
|
else:
|
||||||
|
stock_entry.subcontracting_order = subcontract_order.name
|
||||||
|
|
||||||
|
stock_entry.set_stock_entry_type()
|
||||||
|
|
||||||
|
for fg_item_code in fg_item_code_list:
|
||||||
|
for rm_item in rm_items:
|
||||||
|
|
||||||
|
if rm_item.get("main_item_code") or rm_item.get("item_code") == fg_item_code:
|
||||||
|
rm_item_code = rm_item.get("rm_item_code")
|
||||||
|
|
||||||
|
items_dict = {
|
||||||
|
rm_item_code: {
|
||||||
|
rm_detail_field: rm_item.get("name"),
|
||||||
|
"item_name": rm_item.get("item_name")
|
||||||
|
or item_wh.get(rm_item_code, {}).get("item_name", ""),
|
||||||
|
"description": item_wh.get(rm_item_code, {}).get("description", ""),
|
||||||
|
"qty": rm_item.get("qty")
|
||||||
|
or max(rm_item.get("required_qty") - rm_item.get("total_supplied_qty"), 0),
|
||||||
|
"from_warehouse": rm_item.get("warehouse") or rm_item.get("reserve_warehouse"),
|
||||||
|
"to_warehouse": subcontract_order.supplier_warehouse,
|
||||||
|
"stock_uom": rm_item.get("stock_uom"),
|
||||||
|
"serial_no": rm_item.get("serial_no"),
|
||||||
|
"batch_no": rm_item.get("batch_no"),
|
||||||
|
"main_item_code": fg_item_code,
|
||||||
|
"allow_alternative_item": item_wh.get(rm_item_code, {}).get("allow_alternative_item"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
stock_entry.add_to_stock_entry_detail(items_dict)
|
stock_entry.add_to_stock_entry_detail(items_dict)
|
||||||
return stock_entry.as_dict()
|
|
||||||
else:
|
if target_doc:
|
||||||
frappe.throw(_("No Items selected for transfer"))
|
return stock_entry
|
||||||
return subcontract_order.name
|
else:
|
||||||
|
return stock_entry.as_dict()
|
||||||
|
else:
|
||||||
|
frappe.throw(_("No Items selected for transfer."))
|
||||||
|
|
||||||
|
|
||||||
def add_items_in_ste(
|
def add_items_in_ste(
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import json
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _, msgprint
|
from frappe import _, msgprint
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from frappe.query_builder.functions import IfNull, Sum
|
||||||
from frappe.utils import (
|
from frappe.utils import (
|
||||||
add_days,
|
add_days,
|
||||||
ceil,
|
ceil,
|
||||||
@@ -20,6 +21,7 @@ from frappe.utils import (
|
|||||||
nowdate,
|
nowdate,
|
||||||
)
|
)
|
||||||
from frappe.utils.csvutils import build_csv_response
|
from frappe.utils.csvutils import build_csv_response
|
||||||
|
from pypika.terms import ExistsCriterion
|
||||||
|
|
||||||
from erpnext.manufacturing.doctype.bom.bom import get_children as get_bom_children
|
from erpnext.manufacturing.doctype.bom.bom import get_children as get_bom_children
|
||||||
from erpnext.manufacturing.doctype.bom.bom import validate_bom_no
|
from erpnext.manufacturing.doctype.bom.bom import validate_bom_no
|
||||||
@@ -100,39 +102,46 @@ class ProductionPlan(Document):
|
|||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_pending_material_requests(self):
|
def get_pending_material_requests(self):
|
||||||
"""Pull Material Requests that are pending based on criteria selected"""
|
"""Pull Material Requests that are pending based on criteria selected"""
|
||||||
mr_filter = item_filter = ""
|
|
||||||
|
bom = frappe.qb.DocType("BOM")
|
||||||
|
mr = frappe.qb.DocType("Material Request")
|
||||||
|
mr_item = frappe.qb.DocType("Material Request Item")
|
||||||
|
|
||||||
|
pending_mr_query = (
|
||||||
|
frappe.qb.from_(mr)
|
||||||
|
.from_(mr_item)
|
||||||
|
.select(mr.name, mr.transaction_date)
|
||||||
|
.distinct()
|
||||||
|
.where(
|
||||||
|
(mr_item.parent == mr.name)
|
||||||
|
& (mr.material_request_type == "Manufacture")
|
||||||
|
& (mr.docstatus == 1)
|
||||||
|
& (mr.status != "Stopped")
|
||||||
|
& (mr.company == self.company)
|
||||||
|
& (mr_item.qty > IfNull(mr_item.ordered_qty, 0))
|
||||||
|
& (
|
||||||
|
ExistsCriterion(
|
||||||
|
frappe.qb.from_(bom)
|
||||||
|
.select(bom.name)
|
||||||
|
.where((bom.item == mr_item.item_code) & (bom.is_active == 1))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if self.from_date:
|
if self.from_date:
|
||||||
mr_filter += " and mr.transaction_date >= %(from_date)s"
|
pending_mr_query = pending_mr_query.where(mr.transaction_date >= self.from_date)
|
||||||
|
|
||||||
if self.to_date:
|
if self.to_date:
|
||||||
mr_filter += " and mr.transaction_date <= %(to_date)s"
|
pending_mr_query = pending_mr_query.where(mr.transaction_date <= self.to_date)
|
||||||
|
|
||||||
if self.warehouse:
|
if self.warehouse:
|
||||||
mr_filter += " and mr_item.warehouse = %(warehouse)s"
|
pending_mr_query = pending_mr_query.where(mr_item.warehouse == self.warehouse)
|
||||||
|
|
||||||
if self.item_code:
|
if self.item_code:
|
||||||
item_filter += " and mr_item.item_code = %(item)s"
|
pending_mr_query = pending_mr_query.where(mr_item.item_code == self.item_code)
|
||||||
|
|
||||||
pending_mr = frappe.db.sql(
|
pending_mr = pending_mr_query.run(as_dict=True)
|
||||||
"""
|
|
||||||
select distinct mr.name, mr.transaction_date
|
|
||||||
from `tabMaterial Request` mr, `tabMaterial Request Item` mr_item
|
|
||||||
where mr_item.parent = mr.name
|
|
||||||
and mr.material_request_type = "Manufacture"
|
|
||||||
and mr.docstatus = 1 and mr.status != "Stopped" and mr.company = %(company)s
|
|
||||||
and mr_item.qty > ifnull(mr_item.ordered_qty,0) {0} {1}
|
|
||||||
and (exists (select name from `tabBOM` bom where bom.item=mr_item.item_code
|
|
||||||
and bom.is_active = 1))
|
|
||||||
""".format(
|
|
||||||
mr_filter, item_filter
|
|
||||||
),
|
|
||||||
{
|
|
||||||
"from_date": self.from_date,
|
|
||||||
"to_date": self.to_date,
|
|
||||||
"warehouse": self.warehouse,
|
|
||||||
"item": self.item_code,
|
|
||||||
"company": self.company,
|
|
||||||
},
|
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.add_mr_in_table(pending_mr)
|
self.add_mr_in_table(pending_mr)
|
||||||
|
|
||||||
@@ -160,16 +169,17 @@ class ProductionPlan(Document):
|
|||||||
so_mr_list = [d.get(field) for d in self.get(table) if d.get(field)]
|
so_mr_list = [d.get(field) for d in self.get(table) if d.get(field)]
|
||||||
return so_mr_list
|
return so_mr_list
|
||||||
|
|
||||||
def get_bom_item(self):
|
def get_bom_item_condition(self):
|
||||||
"""Check if Item or if its Template has a BOM."""
|
"""Check if Item or if its Template has a BOM."""
|
||||||
bom_item = None
|
bom_item_condition = None
|
||||||
has_bom = frappe.db.exists({"doctype": "BOM", "item": self.item_code, "docstatus": 1})
|
has_bom = frappe.db.exists({"doctype": "BOM", "item": self.item_code, "docstatus": 1})
|
||||||
|
|
||||||
if not has_bom:
|
if not has_bom:
|
||||||
|
bom = frappe.qb.DocType("BOM")
|
||||||
template_item = frappe.db.get_value("Item", self.item_code, ["variant_of"])
|
template_item = frappe.db.get_value("Item", self.item_code, ["variant_of"])
|
||||||
bom_item = (
|
bom_item_condition = bom.item == template_item or None
|
||||||
"bom.item = {0}".format(frappe.db.escape(template_item)) if template_item else bom_item
|
|
||||||
)
|
return bom_item_condition
|
||||||
return bom_item
|
|
||||||
|
|
||||||
def get_so_items(self):
|
def get_so_items(self):
|
||||||
# Check for empty table or empty rows
|
# Check for empty table or empty rows
|
||||||
@@ -178,46 +188,75 @@ class ProductionPlan(Document):
|
|||||||
|
|
||||||
so_list = self.get_so_mr_list("sales_order", "sales_orders")
|
so_list = self.get_so_mr_list("sales_order", "sales_orders")
|
||||||
|
|
||||||
item_condition = ""
|
bom = frappe.qb.DocType("BOM")
|
||||||
bom_item = "bom.item = so_item.item_code"
|
so_item = frappe.qb.DocType("Sales Order Item")
|
||||||
if self.item_code and frappe.db.exists("Item", self.item_code):
|
|
||||||
bom_item = self.get_bom_item() or bom_item
|
|
||||||
item_condition = " and so_item.item_code = {0}".format(frappe.db.escape(self.item_code))
|
|
||||||
|
|
||||||
items = frappe.db.sql(
|
items_subquery = frappe.qb.from_(bom).select(bom.name).where(bom.is_active == 1)
|
||||||
"""
|
items_query = (
|
||||||
select
|
frappe.qb.from_(so_item)
|
||||||
distinct parent, item_code, warehouse,
|
.select(
|
||||||
(qty - work_order_qty) * conversion_factor as pending_qty,
|
so_item.parent,
|
||||||
description, name
|
so_item.item_code,
|
||||||
from
|
so_item.warehouse,
|
||||||
`tabSales Order Item` so_item
|
(
|
||||||
where
|
(so_item.qty - so_item.work_order_qty - so_item.delivered_qty) * so_item.conversion_factor
|
||||||
parent in (%s) and docstatus = 1 and qty > work_order_qty
|
).as_("pending_qty"),
|
||||||
and exists (select name from `tabBOM` bom where %s
|
so_item.description,
|
||||||
and bom.is_active = 1) %s"""
|
so_item.name,
|
||||||
% (", ".join(["%s"] * len(so_list)), bom_item, item_condition),
|
)
|
||||||
tuple(so_list),
|
.distinct()
|
||||||
as_dict=1,
|
.where(
|
||||||
|
(so_item.parent.isin(so_list))
|
||||||
|
& (so_item.docstatus == 1)
|
||||||
|
& (so_item.qty > so_item.work_order_qty)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.item_code and frappe.db.exists("Item", self.item_code):
|
||||||
|
items_query = items_query.where(so_item.item_code == self.item_code)
|
||||||
|
items_subquery = items_subquery.where(
|
||||||
|
self.get_bom_item_condition() or bom.item == so_item.item_code
|
||||||
|
)
|
||||||
|
|
||||||
|
items_query = items_query.where(ExistsCriterion(items_subquery))
|
||||||
|
|
||||||
|
items = items_query.run(as_dict=True)
|
||||||
|
|
||||||
|
pi = frappe.qb.DocType("Packed Item")
|
||||||
|
|
||||||
|
packed_items_query = (
|
||||||
|
frappe.qb.from_(so_item)
|
||||||
|
.from_(pi)
|
||||||
|
.select(
|
||||||
|
pi.parent,
|
||||||
|
pi.item_code,
|
||||||
|
pi.warehouse.as_("warehouse"),
|
||||||
|
(((so_item.qty - so_item.work_order_qty) * pi.qty) / so_item.qty).as_("pending_qty"),
|
||||||
|
pi.parent_item,
|
||||||
|
pi.description,
|
||||||
|
so_item.name,
|
||||||
|
)
|
||||||
|
.distinct()
|
||||||
|
.where(
|
||||||
|
(so_item.parent == pi.parent)
|
||||||
|
& (so_item.docstatus == 1)
|
||||||
|
& (pi.parent_item == so_item.item_code)
|
||||||
|
& (so_item.parent.isin(so_list))
|
||||||
|
& (so_item.qty > so_item.work_order_qty)
|
||||||
|
& (
|
||||||
|
ExistsCriterion(
|
||||||
|
frappe.qb.from_(bom)
|
||||||
|
.select(bom.name)
|
||||||
|
.where((bom.item == pi.item_code) & (bom.is_active == 1))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.item_code:
|
if self.item_code:
|
||||||
item_condition = " and so_item.item_code = {0}".format(frappe.db.escape(self.item_code))
|
packed_items_query = packed_items_query.where(so_item.item_code == self.item_code)
|
||||||
|
|
||||||
packed_items = frappe.db.sql(
|
packed_items = packed_items_query.run(as_dict=True)
|
||||||
"""select distinct pi.parent, pi.item_code, pi.warehouse as warehouse,
|
|
||||||
(((so_item.qty - so_item.work_order_qty) * pi.qty) / so_item.qty)
|
|
||||||
as pending_qty, pi.parent_item, pi.description, so_item.name
|
|
||||||
from `tabSales Order Item` so_item, `tabPacked Item` pi
|
|
||||||
where so_item.parent = pi.parent and so_item.docstatus = 1
|
|
||||||
and pi.parent_item = so_item.item_code
|
|
||||||
and so_item.parent in (%s) and so_item.qty > so_item.work_order_qty
|
|
||||||
and exists (select name from `tabBOM` bom where bom.item=pi.item_code
|
|
||||||
and bom.is_active = 1) %s"""
|
|
||||||
% (", ".join(["%s"] * len(so_list)), item_condition),
|
|
||||||
tuple(so_list),
|
|
||||||
as_dict=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.add_items(items + packed_items)
|
self.add_items(items + packed_items)
|
||||||
self.calculate_total_planned_qty()
|
self.calculate_total_planned_qty()
|
||||||
@@ -233,22 +272,39 @@ class ProductionPlan(Document):
|
|||||||
|
|
||||||
mr_list = self.get_so_mr_list("material_request", "material_requests")
|
mr_list = self.get_so_mr_list("material_request", "material_requests")
|
||||||
|
|
||||||
item_condition = ""
|
bom = frappe.qb.DocType("BOM")
|
||||||
if self.item_code:
|
mr_item = frappe.qb.DocType("Material Request Item")
|
||||||
item_condition = " and mr_item.item_code ={0}".format(frappe.db.escape(self.item_code))
|
|
||||||
|
|
||||||
items = frappe.db.sql(
|
items_query = (
|
||||||
"""select distinct parent, name, item_code, warehouse, description,
|
frappe.qb.from_(mr_item)
|
||||||
(qty - ordered_qty) * conversion_factor as pending_qty
|
.select(
|
||||||
from `tabMaterial Request Item` mr_item
|
mr_item.parent,
|
||||||
where parent in (%s) and docstatus = 1 and qty > ordered_qty
|
mr_item.name,
|
||||||
and exists (select name from `tabBOM` bom where bom.item=mr_item.item_code
|
mr_item.item_code,
|
||||||
and bom.is_active = 1) %s"""
|
mr_item.warehouse,
|
||||||
% (", ".join(["%s"] * len(mr_list)), item_condition),
|
mr_item.description,
|
||||||
tuple(mr_list),
|
((mr_item.qty - mr_item.ordered_qty) * mr_item.conversion_factor).as_("pending_qty"),
|
||||||
as_dict=1,
|
)
|
||||||
|
.distinct()
|
||||||
|
.where(
|
||||||
|
(mr_item.parent.isin(mr_list))
|
||||||
|
& (mr_item.docstatus == 1)
|
||||||
|
& (mr_item.qty > mr_item.ordered_qty)
|
||||||
|
& (
|
||||||
|
ExistsCriterion(
|
||||||
|
frappe.qb.from_(bom)
|
||||||
|
.select(bom.name)
|
||||||
|
.where((bom.item == mr_item.item_code) & (bom.is_active == 1))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self.item_code:
|
||||||
|
items_query = items_query.where(mr_item.item_code == self.item_code)
|
||||||
|
|
||||||
|
items = items_query.run(as_dict=True)
|
||||||
|
|
||||||
self.add_items(items)
|
self.add_items(items)
|
||||||
self.calculate_total_planned_qty()
|
self.calculate_total_planned_qty()
|
||||||
|
|
||||||
@@ -819,29 +875,45 @@ def download_raw_materials(doc, warehouses=None):
|
|||||||
|
|
||||||
|
|
||||||
def get_exploded_items(item_details, company, bom_no, include_non_stock_items, planned_qty=1):
|
def get_exploded_items(item_details, company, bom_no, include_non_stock_items, planned_qty=1):
|
||||||
for d in frappe.db.sql(
|
bei = frappe.qb.DocType("BOM Explosion Item")
|
||||||
"""select bei.item_code, item.default_bom as bom,
|
bom = frappe.qb.DocType("BOM")
|
||||||
ifnull(sum(bei.stock_qty/ifnull(bom.quantity, 1)), 0)*%s as qty, item.item_name,
|
item = frappe.qb.DocType("Item")
|
||||||
bei.description, bei.stock_uom, item.min_order_qty, bei.source_warehouse,
|
item_default = frappe.qb.DocType("Item Default")
|
||||||
item.default_material_request_type, item.min_order_qty, item_default.default_warehouse,
|
item_uom = frappe.qb.DocType("UOM Conversion Detail")
|
||||||
item.purchase_uom, item_uom.conversion_factor, item.safety_stock
|
|
||||||
from
|
data = (
|
||||||
`tabBOM Explosion Item` bei
|
frappe.qb.from_(bei)
|
||||||
JOIN `tabBOM` bom ON bom.name = bei.parent
|
.join(bom)
|
||||||
JOIN `tabItem` item ON item.name = bei.item_code
|
.on(bom.name == bei.parent)
|
||||||
LEFT JOIN `tabItem Default` item_default
|
.join(item)
|
||||||
ON item_default.parent = item.name and item_default.company=%s
|
.on(item.name == bei.item_code)
|
||||||
LEFT JOIN `tabUOM Conversion Detail` item_uom
|
.left_join(item_default)
|
||||||
ON item.name = item_uom.parent and item_uom.uom = item.purchase_uom
|
.on((item_default.parent == item.name) & (item_default.company == company))
|
||||||
where
|
.left_join(item_uom)
|
||||||
bei.docstatus < 2
|
.on((item.name == item_uom.parent) & (item_uom.uom == item.purchase_uom))
|
||||||
and bom.name=%s and item.is_stock_item in (1, {0})
|
.select(
|
||||||
group by bei.item_code, bei.stock_uom""".format(
|
(IfNull(Sum(bei.stock_qty / IfNull(bom.quantity, 1)), 0) * planned_qty).as_("qty"),
|
||||||
0 if include_non_stock_items else 1
|
item.item_name,
|
||||||
),
|
bei.description,
|
||||||
(planned_qty, company, bom_no),
|
bei.stock_uom,
|
||||||
as_dict=1,
|
item.min_order_qty,
|
||||||
):
|
bei.source_warehouse,
|
||||||
|
item.default_material_request_type,
|
||||||
|
item.min_order_qty,
|
||||||
|
item_default.default_warehouse,
|
||||||
|
item.purchase_uom,
|
||||||
|
item_uom.conversion_factor,
|
||||||
|
item.safety_stock,
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
(bei.docstatus < 2)
|
||||||
|
& (bom.name == bom_no)
|
||||||
|
& (item.is_stock_item.isin([0, 1]) if include_non_stock_items else item.is_stock_item == 1)
|
||||||
|
)
|
||||||
|
.groupby(bei.item_code, bei.stock_uom)
|
||||||
|
).run(as_dict=True)
|
||||||
|
|
||||||
|
for d in data:
|
||||||
if not d.conversion_factor and d.purchase_uom:
|
if not d.conversion_factor and d.purchase_uom:
|
||||||
d.conversion_factor = get_uom_conversion_factor(d.item_code, d.purchase_uom)
|
d.conversion_factor = get_uom_conversion_factor(d.item_code, d.purchase_uom)
|
||||||
item_details.setdefault(d.get("item_code"), d)
|
item_details.setdefault(d.get("item_code"), d)
|
||||||
@@ -866,33 +938,47 @@ def get_subitems(
|
|||||||
parent_qty,
|
parent_qty,
|
||||||
planned_qty=1,
|
planned_qty=1,
|
||||||
):
|
):
|
||||||
items = frappe.db.sql(
|
bom_item = frappe.qb.DocType("BOM Item")
|
||||||
"""
|
bom = frappe.qb.DocType("BOM")
|
||||||
SELECT
|
item = frappe.qb.DocType("Item")
|
||||||
bom_item.item_code, default_material_request_type, item.item_name,
|
item_default = frappe.qb.DocType("Item Default")
|
||||||
ifnull(%(parent_qty)s * sum(bom_item.stock_qty/ifnull(bom.quantity, 1)) * %(planned_qty)s, 0) as qty,
|
item_uom = frappe.qb.DocType("UOM Conversion Detail")
|
||||||
item.is_sub_contracted_item as is_sub_contracted, bom_item.source_warehouse,
|
|
||||||
item.default_bom as default_bom, bom_item.description as description,
|
items = (
|
||||||
bom_item.stock_uom as stock_uom, item.min_order_qty as min_order_qty, item.safety_stock as safety_stock,
|
frappe.qb.from_(bom_item)
|
||||||
item_default.default_warehouse, item.purchase_uom, item_uom.conversion_factor
|
.join(bom)
|
||||||
FROM
|
.on(bom.name == bom_item.parent)
|
||||||
`tabBOM Item` bom_item
|
.join(item)
|
||||||
JOIN `tabBOM` bom ON bom.name = bom_item.parent
|
.on(bom_item.item_code == item.name)
|
||||||
JOIN `tabItem` item ON bom_item.item_code = item.name
|
.left_join(item_default)
|
||||||
LEFT JOIN `tabItem Default` item_default
|
.on((item.name == item_default.parent) & (item_default.company == company))
|
||||||
ON item.name = item_default.parent and item_default.company = %(company)s
|
.left_join(item_uom)
|
||||||
LEFT JOIN `tabUOM Conversion Detail` item_uom
|
.on((item.name == item_uom.parent) & (item_uom.uom == item.purchase_uom))
|
||||||
ON item.name = item_uom.parent and item_uom.uom = item.purchase_uom
|
.select(
|
||||||
where
|
bom_item.item_code,
|
||||||
bom.name = %(bom)s
|
item.default_material_request_type,
|
||||||
and bom_item.docstatus < 2
|
item.item_name,
|
||||||
and item.is_stock_item in (1, {0})
|
IfNull(parent_qty * Sum(bom_item.stock_qty / IfNull(bom.quantity, 1)) * planned_qty, 0).as_(
|
||||||
group by bom_item.item_code""".format(
|
"qty"
|
||||||
0 if include_non_stock_items else 1
|
),
|
||||||
),
|
item.is_sub_contracted_item.as_("is_sub_contracted"),
|
||||||
{"bom": bom_no, "parent_qty": parent_qty, "planned_qty": planned_qty, "company": company},
|
bom_item.source_warehouse,
|
||||||
as_dict=1,
|
item.default_bom.as_("default_bom"),
|
||||||
)
|
bom_item.description.as_("description"),
|
||||||
|
bom_item.stock_uom.as_("stock_uom"),
|
||||||
|
item.min_order_qty.as_("min_order_qty"),
|
||||||
|
item.safety_stock.as_("safety_stock"),
|
||||||
|
item_default.default_warehouse,
|
||||||
|
item.purchase_uom,
|
||||||
|
item_uom.conversion_factor,
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
(bom.name == bom_no)
|
||||||
|
& (bom_item.docstatus < 2)
|
||||||
|
& (item.is_stock_item.isin([0, 1]) if include_non_stock_items else item.is_stock_item == 1)
|
||||||
|
)
|
||||||
|
.groupby(bom_item.item_code)
|
||||||
|
).run(as_dict=True)
|
||||||
|
|
||||||
for d in items:
|
for d in items:
|
||||||
if not data.get("include_exploded_items") or not d.default_bom:
|
if not data.get("include_exploded_items") or not d.default_bom:
|
||||||
@@ -980,48 +1066,69 @@ def get_material_request_items(
|
|||||||
|
|
||||||
|
|
||||||
def get_sales_orders(self):
|
def get_sales_orders(self):
|
||||||
so_filter = item_filter = ""
|
bom = frappe.qb.DocType("BOM")
|
||||||
bom_item = "bom.item = so_item.item_code"
|
pi = frappe.qb.DocType("Packed Item")
|
||||||
|
so = frappe.qb.DocType("Sales Order")
|
||||||
|
so_item = frappe.qb.DocType("Sales Order Item")
|
||||||
|
|
||||||
|
open_so_subquery1 = frappe.qb.from_(bom).select(bom.name).where(bom.is_active == 1)
|
||||||
|
|
||||||
|
open_so_subquery2 = (
|
||||||
|
frappe.qb.from_(pi)
|
||||||
|
.select(pi.name)
|
||||||
|
.where(
|
||||||
|
(pi.parent == so.name)
|
||||||
|
& (pi.parent_item == so_item.item_code)
|
||||||
|
& (
|
||||||
|
ExistsCriterion(
|
||||||
|
frappe.qb.from_(bom).select(bom.name).where((bom.item == pi.item_code) & (bom.is_active == 1))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
open_so_query = (
|
||||||
|
frappe.qb.from_(so)
|
||||||
|
.from_(so_item)
|
||||||
|
.select(so.name, so.transaction_date, so.customer, so.base_grand_total)
|
||||||
|
.distinct()
|
||||||
|
.where(
|
||||||
|
(so_item.parent == so.name)
|
||||||
|
& (so.docstatus == 1)
|
||||||
|
& (so.status.notin(["Stopped", "Closed"]))
|
||||||
|
& (so.company == self.company)
|
||||||
|
& (so_item.qty > so_item.work_order_qty)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
date_field_mapper = {
|
date_field_mapper = {
|
||||||
"from_date": (">=", "so.transaction_date"),
|
"from_date": self.from_date >= so.transaction_date,
|
||||||
"to_date": ("<=", "so.transaction_date"),
|
"to_date": self.to_date <= so.transaction_date,
|
||||||
"from_delivery_date": (">=", "so_item.delivery_date"),
|
"from_delivery_date": self.from_delivery_date >= so_item.delivery_date,
|
||||||
"to_delivery_date": ("<=", "so_item.delivery_date"),
|
"to_delivery_date": self.to_delivery_date <= so_item.delivery_date,
|
||||||
}
|
}
|
||||||
|
|
||||||
for field, value in date_field_mapper.items():
|
for field, value in date_field_mapper.items():
|
||||||
if self.get(field):
|
if self.get(field):
|
||||||
so_filter += f" and {value[1]} {value[0]} %({field})s"
|
open_so_query = open_so_query.where(value)
|
||||||
|
|
||||||
for field in ["customer", "project", "sales_order_status"]:
|
for field in ("customer", "project", "sales_order_status"):
|
||||||
if self.get(field):
|
if self.get(field):
|
||||||
so_field = "status" if field == "sales_order_status" else field
|
so_field = "status" if field == "sales_order_status" else field
|
||||||
so_filter += f" and so.{so_field} = %({field})s"
|
open_so_query = open_so_query.where(so[so_field] == self.get(field))
|
||||||
|
|
||||||
if self.item_code and frappe.db.exists("Item", self.item_code):
|
if self.item_code and frappe.db.exists("Item", self.item_code):
|
||||||
bom_item = self.get_bom_item() or bom_item
|
open_so_query = open_so_query.where(so_item.item_code == self.item_code)
|
||||||
item_filter += " and so_item.item_code = %(item_code)s"
|
open_so_subquery1 = open_so_subquery1.where(
|
||||||
|
self.get_bom_item_condition() or bom.item == so_item.item_code
|
||||||
|
)
|
||||||
|
|
||||||
open_so = frappe.db.sql(
|
open_so_query = open_so_query.where(
|
||||||
f"""
|
(ExistsCriterion(open_so_subquery1) | ExistsCriterion(open_so_subquery2))
|
||||||
select distinct so.name, so.transaction_date, so.customer, so.base_grand_total
|
|
||||||
from `tabSales Order` so, `tabSales Order Item` so_item
|
|
||||||
where so_item.parent = so.name
|
|
||||||
and so.docstatus = 1 and so.status not in ('Stopped', 'Closed')
|
|
||||||
and so.company = %(company)s
|
|
||||||
and so_item.qty > so_item.work_order_qty {so_filter} {item_filter}
|
|
||||||
and (exists (select name from `tabBOM` bom where {bom_item}
|
|
||||||
and bom.is_active = 1)
|
|
||||||
or exists (select name from `tabPacked Item` pi
|
|
||||||
where pi.parent = so.name and pi.parent_item = so_item.item_code
|
|
||||||
and exists (select name from `tabBOM` bom where bom.item=pi.item_code
|
|
||||||
and bom.is_active = 1)))
|
|
||||||
""",
|
|
||||||
self.as_dict(),
|
|
||||||
as_dict=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
open_so = open_so_query.run(as_dict=True)
|
||||||
|
|
||||||
return open_so
|
return open_so
|
||||||
|
|
||||||
|
|
||||||
@@ -1030,37 +1137,34 @@ def get_bin_details(row, company, for_warehouse=None, all_warehouse=False):
|
|||||||
if isinstance(row, str):
|
if isinstance(row, str):
|
||||||
row = frappe._dict(json.loads(row))
|
row = frappe._dict(json.loads(row))
|
||||||
|
|
||||||
company = frappe.db.escape(company)
|
bin = frappe.qb.DocType("Bin")
|
||||||
conditions, warehouse = "", ""
|
wh = frappe.qb.DocType("Warehouse")
|
||||||
|
|
||||||
|
subquery = frappe.qb.from_(wh).select(wh.name).where(wh.company == company)
|
||||||
|
|
||||||
conditions = " and warehouse in (select name from `tabWarehouse` where company = {0})".format(
|
|
||||||
company
|
|
||||||
)
|
|
||||||
if not all_warehouse:
|
if not all_warehouse:
|
||||||
warehouse = for_warehouse or row.get("source_warehouse") or row.get("default_warehouse")
|
warehouse = for_warehouse or row.get("source_warehouse") or row.get("default_warehouse")
|
||||||
|
|
||||||
if warehouse:
|
if warehouse:
|
||||||
lft, rgt = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"])
|
lft, rgt = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"])
|
||||||
conditions = """ and warehouse in (select name from `tabWarehouse`
|
subquery = subquery.where((wh.lft >= lft) & (wh.rgt <= rgt) & (wh.name == bin.warehouse))
|
||||||
where lft >= {0} and rgt <= {1} and name=`tabBin`.warehouse and company = {2})
|
|
||||||
""".format(
|
|
||||||
lft, rgt, company
|
|
||||||
)
|
|
||||||
|
|
||||||
return frappe.db.sql(
|
query = (
|
||||||
""" select ifnull(sum(projected_qty),0) as projected_qty,
|
frappe.qb.from_(bin)
|
||||||
ifnull(sum(actual_qty),0) as actual_qty, ifnull(sum(ordered_qty),0) as ordered_qty,
|
.select(
|
||||||
ifnull(sum(reserved_qty_for_production),0) as reserved_qty_for_production, warehouse,
|
bin.warehouse,
|
||||||
ifnull(sum(planned_qty),0) as planned_qty
|
IfNull(Sum(bin.projected_qty), 0).as_("projected_qty"),
|
||||||
from `tabBin` where item_code = %(item_code)s {conditions}
|
IfNull(Sum(bin.actual_qty), 0).as_("actual_qty"),
|
||||||
group by item_code, warehouse
|
IfNull(Sum(bin.ordered_qty), 0).as_("ordered_qty"),
|
||||||
""".format(
|
IfNull(Sum(bin.reserved_qty_for_production), 0).as_("reserved_qty_for_production"),
|
||||||
conditions=conditions
|
IfNull(Sum(bin.planned_qty), 0).as_("planned_qty"),
|
||||||
),
|
)
|
||||||
{"item_code": row["item_code"]},
|
.where((bin.item_code == row["item_code"]) & (bin.warehouse.isin(subquery)))
|
||||||
as_dict=1,
|
.groupby(bin.item_code, bin.warehouse)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return query.run(as_dict=True)
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_so_details(sales_order):
|
def get_so_details(sales_order):
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from erpnext.manufacturing.doctype.production_plan.production_plan import (
|
|||||||
)
|
)
|
||||||
from erpnext.manufacturing.doctype.work_order.work_order import OverProductionError
|
from erpnext.manufacturing.doctype.work_order.work_order import OverProductionError
|
||||||
from erpnext.manufacturing.doctype.work_order.work_order import make_stock_entry as make_se_from_wo
|
from erpnext.manufacturing.doctype.work_order.work_order import make_stock_entry as make_se_from_wo
|
||||||
|
from erpnext.selling.doctype.sales_order.sales_order import make_delivery_note
|
||||||
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
|
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
|
||||||
from erpnext.stock.doctype.item.test_item import create_item, make_item
|
from erpnext.stock.doctype.item.test_item import create_item, make_item
|
||||||
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
|
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
|
||||||
@@ -610,15 +611,21 @@ class TestProductionPlan(FrappeTestCase):
|
|||||||
"""
|
"""
|
||||||
from erpnext.manufacturing.doctype.work_order.test_work_order import make_wo_order_test_record
|
from erpnext.manufacturing.doctype.work_order.test_work_order import make_wo_order_test_record
|
||||||
|
|
||||||
|
make_stock_entry(item_code="_Test Item", target="Work In Progress - _TC", qty=2, basic_rate=100)
|
||||||
make_stock_entry(
|
make_stock_entry(
|
||||||
item_code="Raw Material Item 1", target="Work In Progress - _TC", qty=2, basic_rate=100
|
item_code="_Test Item Home Desktop 100", target="Work In Progress - _TC", qty=4, basic_rate=100
|
||||||
)
|
|
||||||
make_stock_entry(
|
|
||||||
item_code="Raw Material Item 2", target="Work In Progress - _TC", qty=2, basic_rate=100
|
|
||||||
)
|
)
|
||||||
|
|
||||||
item = "Test Production Item 1"
|
item = "_Test FG Item"
|
||||||
so = make_sales_order(item_code=item, qty=1)
|
|
||||||
|
make_stock_entry(item_code=item, target="_Test Warehouse - _TC", qty=1)
|
||||||
|
|
||||||
|
so = make_sales_order(item_code=item, qty=2)
|
||||||
|
|
||||||
|
dn = make_delivery_note(so.name)
|
||||||
|
dn.items[0].qty = 1
|
||||||
|
dn.save()
|
||||||
|
dn.submit()
|
||||||
|
|
||||||
pln = create_production_plan(
|
pln = create_production_plan(
|
||||||
company=so.company, get_items_from="Sales Order", sales_order=so, skip_getting_mr_items=True
|
company=so.company, get_items_from="Sales Order", sales_order=so, skip_getting_mr_items=True
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ function open_form(frm, doctype, child_doctype, parentfield) {
|
|||||||
new_child_doc.parentfield = parentfield;
|
new_child_doc.parentfield = parentfield;
|
||||||
new_child_doc.parenttype = doctype;
|
new_child_doc.parenttype = doctype;
|
||||||
new_doc[parentfield] = [new_child_doc];
|
new_doc[parentfield] = [new_child_doc];
|
||||||
|
new_doc.project = frm.doc.name;
|
||||||
|
|
||||||
frappe.ui.form.make_quick_entry(doctype, null, null, new_doc);
|
frappe.ui.form.make_quick_entry(doctype, null, null, new_doc);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1492,7 +1492,17 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
|||||||
frappe.model.set_value(child.doctype, child.name, "rate", value);
|
frappe.model.set_value(child.doctype, child.name, "rate", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (key === "pricing_rules") {
|
||||||
|
frappe.model.set_value(child.doctype, child.name, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
if (key !== "free_item_data") {
|
if (key !== "free_item_data") {
|
||||||
|
if (child.apply_rule_on_other_items && JSON.parse(child.apply_rule_on_other_items).length) {
|
||||||
|
if (!in_list(JSON.parse(child.apply_rule_on_other_items), child.item_code)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
frappe.model.set_value(child.doctype, child.name, key, value);
|
frappe.model.set_value(child.doctype, child.name, key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1510,11 +1520,11 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
|||||||
this.remove_pricing_rule(frappe.get_doc(child.doctype, child.name));
|
this.remove_pricing_rule(frappe.get_doc(child.doctype, child.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (child.free_item_data.length > 0) {
|
if (child.free_item_data && child.free_item_data.length > 0) {
|
||||||
this.apply_product_discount(child);
|
this.apply_product_discount(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (child.apply_rule_on_other_items) {
|
if (child.apply_rule_on_other_items && JSON.parse(child.apply_rule_on_other_items).length) {
|
||||||
items_rule_dict[child.name] = child;
|
items_rule_dict[child.name] = child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1530,11 +1540,11 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
|||||||
for(var k in args) {
|
for(var k in args) {
|
||||||
let data = args[k];
|
let data = args[k];
|
||||||
|
|
||||||
if (data && data.apply_rule_on_other_items) {
|
if (data && data.apply_rule_on_other_items && JSON.parse(data.apply_rule_on_other_items)) {
|
||||||
me.frm.doc.items.forEach(d => {
|
me.frm.doc.items.forEach(d => {
|
||||||
if (in_list(data.apply_rule_on_other_items, d[data.apply_rule_on])) {
|
if (in_list(JSON.parse(data.apply_rule_on_other_items), d[data.apply_rule_on])) {
|
||||||
for(var k in data) {
|
for(var k in data) {
|
||||||
if (in_list(fields, k) && data[k] && (data.price_or_product_discount === 'price' || k === 'pricing_rules')) {
|
if (in_list(fields, k) && data[k] && (data.price_or_product_discount === 'Price' || k === 'pricing_rules')) {
|
||||||
frappe.model.set_value(d.doctype, d.name, k, data[k]);
|
frappe.model.set_value(d.doctype, d.name, k, data[k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -880,6 +880,9 @@ def get_events(start, end, filters=None):
|
|||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def make_purchase_order_for_default_supplier(source_name, selected_items=None, target_doc=None):
|
def make_purchase_order_for_default_supplier(source_name, selected_items=None, target_doc=None):
|
||||||
"""Creates Purchase Order for each Supplier. Returns a list of doc objects."""
|
"""Creates Purchase Order for each Supplier. Returns a list of doc objects."""
|
||||||
|
|
||||||
|
from erpnext.setup.utils import get_exchange_rate
|
||||||
|
|
||||||
if not selected_items:
|
if not selected_items:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -888,6 +891,15 @@ def make_purchase_order_for_default_supplier(source_name, selected_items=None, t
|
|||||||
|
|
||||||
def set_missing_values(source, target):
|
def set_missing_values(source, target):
|
||||||
target.supplier = supplier
|
target.supplier = supplier
|
||||||
|
target.currency = frappe.db.get_value(
|
||||||
|
"Supplier", filters={"name": supplier}, fieldname=["default_currency"]
|
||||||
|
)
|
||||||
|
company_currency = frappe.db.get_value(
|
||||||
|
"Company", filters={"name": target.company}, fieldname=["default_currency"]
|
||||||
|
)
|
||||||
|
|
||||||
|
target.conversion_rate = get_exchange_rate(target.currency, company_currency, args="for_buying")
|
||||||
|
|
||||||
target.apply_discount_on = ""
|
target.apply_discount_on = ""
|
||||||
target.additional_discount_percentage = 0.0
|
target.additional_discount_percentage = 0.0
|
||||||
target.discount_amount = 0.0
|
target.discount_amount = 0.0
|
||||||
|
|||||||
@@ -625,6 +625,12 @@ frappe.ui.form.on('Stock Entry', {
|
|||||||
purchase_order: (frm) => {
|
purchase_order: (frm) => {
|
||||||
if (frm.doc.purchase_order) {
|
if (frm.doc.purchase_order) {
|
||||||
frm.set_value("subcontracting_order", "");
|
frm.set_value("subcontracting_order", "");
|
||||||
|
erpnext.utils.map_current_doc({
|
||||||
|
method: 'erpnext.stock.doctype.stock_entry.stock_entry.get_items_from_subcontract_order',
|
||||||
|
source_name: frm.doc.purchase_order,
|
||||||
|
target_doc: frm,
|
||||||
|
freeze: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -632,7 +638,7 @@ frappe.ui.form.on('Stock Entry', {
|
|||||||
if (frm.doc.subcontracting_order) {
|
if (frm.doc.subcontracting_order) {
|
||||||
frm.set_value("purchase_order", "");
|
frm.set_value("purchase_order", "");
|
||||||
erpnext.utils.map_current_doc({
|
erpnext.utils.map_current_doc({
|
||||||
method: 'erpnext.stock.doctype.stock_entry.stock_entry.get_items_from_subcontracting_order',
|
method: 'erpnext.stock.doctype.stock_entry.stock_entry.get_items_from_subcontract_order',
|
||||||
source_name: frm.doc.subcontracting_order,
|
source_name: frm.doc.subcontracting_order,
|
||||||
target_doc: frm,
|
target_doc: frm,
|
||||||
freeze: true,
|
freeze: true,
|
||||||
|
|||||||
@@ -919,6 +919,16 @@ class StockEntry(StockController):
|
|||||||
)
|
)
|
||||||
if order_rm_detail:
|
if order_rm_detail:
|
||||||
se_item.db_set(self.subcontract_data.rm_detail_field, order_rm_detail)
|
se_item.db_set(self.subcontract_data.rm_detail_field, order_rm_detail)
|
||||||
|
else:
|
||||||
|
if not se_item.allow_alternative_item:
|
||||||
|
frappe.throw(
|
||||||
|
_("Row {0}# Item {1} not found in 'Raw Materials Supplied' table in {2} {3}").format(
|
||||||
|
se_item.idx,
|
||||||
|
se_item.item_code,
|
||||||
|
self.subcontract_data.order_doctype,
|
||||||
|
self.get(self.subcontract_data.order_field),
|
||||||
|
)
|
||||||
|
)
|
||||||
elif backflush_raw_materials_based_on == "Material Transferred for Subcontract":
|
elif backflush_raw_materials_based_on == "Material Transferred for Subcontract":
|
||||||
for row in self.items:
|
for row in self.items:
|
||||||
if not row.subcontracted_item:
|
if not row.subcontracted_item:
|
||||||
@@ -1935,6 +1945,8 @@ class StockEntry(StockController):
|
|||||||
se_child.is_finished_item = item_row.get("is_finished_item", 0)
|
se_child.is_finished_item = item_row.get("is_finished_item", 0)
|
||||||
se_child.is_scrap_item = item_row.get("is_scrap_item", 0)
|
se_child.is_scrap_item = item_row.get("is_scrap_item", 0)
|
||||||
se_child.is_process_loss = item_row.get("is_process_loss", 0)
|
se_child.is_process_loss = item_row.get("is_process_loss", 0)
|
||||||
|
se_child.po_detail = item_row.get("po_detail")
|
||||||
|
se_child.sco_rm_detail = item_row.get("sco_rm_detail")
|
||||||
|
|
||||||
for field in [
|
for field in [
|
||||||
self.subcontract_data.rm_detail_field,
|
self.subcontract_data.rm_detail_field,
|
||||||
@@ -2581,49 +2593,15 @@ def get_supplied_items(
|
|||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_items_from_subcontracting_order(source_name, target_doc=None):
|
def get_items_from_subcontract_order(source_name, target_doc=None):
|
||||||
def post_process(source, target):
|
from erpnext.controllers.subcontracting_controller import make_rm_stock_entry
|
||||||
target.stock_entry_type = target.purpose = "Send to Subcontractor"
|
|
||||||
target.subcontracting_order = source_name
|
|
||||||
|
|
||||||
if target.items:
|
if isinstance(target_doc, str):
|
||||||
target.items = []
|
target_doc = frappe.get_doc(json.loads(target_doc))
|
||||||
|
|
||||||
warehouses = {}
|
order_doctype = "Purchase Order" if target_doc.purchase_order else "Subcontracting Order"
|
||||||
for item in source.items:
|
target_doc = make_rm_stock_entry(
|
||||||
warehouses[item.name] = item.warehouse
|
subcontract_order=source_name, order_doctype=order_doctype, target_doc=target_doc
|
||||||
|
|
||||||
for item in source.supplied_items:
|
|
||||||
target.append(
|
|
||||||
"items",
|
|
||||||
{
|
|
||||||
"s_warehouse": warehouses.get(item.reference_name),
|
|
||||||
"t_warehouse": source.supplier_warehouse,
|
|
||||||
"subcontracted_item": item.main_item_code,
|
|
||||||
"item_code": item.rm_item_code,
|
|
||||||
"qty": max(item.required_qty - item.total_supplied_qty, 0),
|
|
||||||
"transfer_qty": item.required_qty,
|
|
||||||
"uom": item.stock_uom,
|
|
||||||
"stock_uom": item.stock_uom,
|
|
||||||
"conversion_factor": 1,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
target_doc = get_mapped_doc(
|
|
||||||
"Subcontracting Order",
|
|
||||||
source_name,
|
|
||||||
{
|
|
||||||
"Subcontracting Order": {
|
|
||||||
"doctype": "Stock Entry",
|
|
||||||
"field_no_map": ["purchase_order"],
|
|
||||||
"validation": {
|
|
||||||
"docstatus": ["=", 1],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
target_doc,
|
|
||||||
post_process,
|
|
||||||
ignore_child_tables=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return target_doc
|
return target_doc
|
||||||
|
|||||||
@@ -205,20 +205,10 @@ erpnext.buying.SubcontractingOrderController = class SubcontractingOrderControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
make_stock_entry() {
|
make_stock_entry() {
|
||||||
frappe.model.open_mapped_doc({
|
|
||||||
method: 'erpnext.stock.doctype.stock_entry.stock_entry.get_items_from_subcontracting_order',
|
|
||||||
source_name: cur_frm.doc.name,
|
|
||||||
freeze: true,
|
|
||||||
freeze_message: __('Creating Stock Entry ...')
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
make_rm_stock_entry(rm_items) {
|
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: 'erpnext.controllers.subcontracting_controller.make_rm_stock_entry',
|
method: 'erpnext.controllers.subcontracting_controller.make_rm_stock_entry',
|
||||||
args: {
|
args: {
|
||||||
subcontract_order: cur_frm.doc.name,
|
subcontract_order: cur_frm.doc.name,
|
||||||
rm_items: rm_items,
|
|
||||||
order_doctype: cur_frm.doc.doctype
|
order_doctype: cur_frm.doc.doctype
|
||||||
},
|
},
|
||||||
callback: (r) => {
|
callback: (r) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user