feat: added jinja method get_serial_or_batch_nos for print format and new print format 'Purchase Receipt Serial and Batch Bundle Print for reference

This commit is contained in:
Rohit Waghchaure 2023-06-02 00:11:43 +05:30
parent 40ab3bdd35
commit bb95451db6
9 changed files with 66 additions and 21 deletions

View File

@ -67,6 +67,12 @@ treeviews = [
"Department",
]
jinja = {
"methods": [
"erpnext.stock.serial_batch_bundle.get_serial_or_batch_nos",
],
}
# website
update_website_context = [
"erpnext.e_commerce.shopping_cart.utils.update_website_context",

View File

@ -300,20 +300,10 @@ erpnext.selling.SellingController = class SellingController extends erpnext.Tran
conversion_factor(doc, cdt, cdn, dont_fetch_price_list_rate) {
super.conversion_factor(doc, cdt, cdn, dont_fetch_price_list_rate);
if(frappe.meta.get_docfield(cdt, "stock_qty", cdn) &&
in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) {
if (doc.doctype === 'Sales Invoice' && (!doc.update_stock)) return;
this.set_batch_number(cdt, cdn);
}
}
qty(doc, cdt, cdn) {
super.qty(doc, cdt, cdn);
if(in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) {
if (doc.doctype === 'Sales Invoice' && (!doc.update_stock)) return;
this.set_batch_number(cdt, cdn);
}
}
pick_serial_and_batch(doc, cdt, cdn) {

View File

@ -52,6 +52,7 @@ class StockLedgerEntry(Document):
def on_submit(self):
self.check_stock_frozen_date()
# Added to handle few test cases where serial_and_batch_bundles are not required
if frappe.flags.in_test and frappe.flags.ignore_serial_batch_bundle_validation:
return

View File

@ -297,6 +297,7 @@ def create_material_receipt(
se.set_stock_entry_type()
se.insert()
se.submit()
se.reload()
return se

View File

@ -22,35 +22,41 @@ def get_columns(filters):
"fieldtype": "Link",
"fieldname": "voucher_type",
"options": "DocType",
"width": 220,
"width": 160,
},
{
"label": _("Voucher No"),
"fieldtype": "Dynamic Link",
"fieldname": "voucher_no",
"options": "voucher_type",
"width": 220,
"width": 180,
},
{
"label": _("Company"),
"fieldtype": "Link",
"fieldname": "company",
"options": "Company",
"width": 220,
"width": 150,
},
{
"label": _("Warehouse"),
"fieldtype": "Link",
"fieldname": "warehouse",
"options": "Warehouse",
"width": 220,
"width": 150,
},
{
"label": _("Serial No"),
"fieldtype": "Link",
"fieldname": "serial_no",
"options": "Serial No",
"width": 220,
"width": 150,
},
{
"label": _("Valuation Rate"),
"fieldtype": "Float",
"fieldname": "valuation_rate",
"width": 150,
},
]
@ -84,14 +90,16 @@ def get_data(filters):
serial_nos = bundle_wise_serial_nos.get(row.serial_and_batch_bundle, [])
for index, serial_no in enumerate(serial_nos):
for index, bundle_data in enumerate(serial_nos):
if index == 0:
args.serial_no = serial_no
args.serial_no = bundle_data.get("serial_no")
args.valuation_rate = bundle_data.get("valuation_rate")
data.append(args)
else:
data.append(
{
"serial_no": serial_no,
"serial_no": bundle_data.get("serial_no"),
"valuation_rate": bundle_data.get("valuation_rate"),
}
)
@ -106,10 +114,15 @@ def get_serial_nos(filters, serial_bundle_ids):
for d in frappe.get_all(
"Serial and Batch Entry",
fields=["serial_no", "parent"],
fields=["serial_no", "parent", "stock_value_difference as valuation_rate"],
filters=bundle_filters,
order_by="idx asc",
):
bundle_wise_serial_nos.setdefault(d.parent, []).append(d.serial_no)
bundle_wise_serial_nos.setdefault(d.parent, []).append(
{
"serial_no": d.serial_no,
"valuation_rate": abs(d.valuation_rate),
}
)
return bundle_wise_serial_nos

View File

@ -296,6 +296,10 @@ def get_serial_nos_from_bundle(serial_and_batch_bundle, serial_nos=None):
return get_serial_nos(serial_and_batch_bundle, serial_nos=serial_nos)
def get_serial_or_batch_nos(bundle):
return frappe.get_all("Serial and Batch Entry", fields=["*"], filters={"parent": bundle})
class SerialNoValuation(DeprecatedSerialNoValuation):
def __init__(self, **kwargs):
for key, value in kwargs.items():

View File

@ -8,10 +8,10 @@ from typing import Optional, Set, Tuple
import frappe
from frappe import _, scrub
from frappe.model.meta import get_field_precision
from frappe.query_builder import Case
from frappe.query_builder.functions import CombineDatetime, Sum
from frappe.utils import (
cint,
cstr,
flt,
get_link_to_form,
getdate,