Merge branch 'develop' into pp-wo-company

This commit is contained in:
Marica 2022-04-13 11:52:15 +05:30 committed by GitHub
commit c5247a0767
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 65 additions and 23 deletions

View File

@ -205,10 +205,16 @@ def get_doctypes_with_dimensions():
return frappe.get_hooks("accounting_dimension_doctypes") return frappe.get_hooks("accounting_dimension_doctypes")
def get_accounting_dimensions(as_list=True): def get_accounting_dimensions(as_list=True, filters=None):
if not filters:
filters = {"disabled": 0}
if frappe.flags.accounting_dimensions is None: if frappe.flags.accounting_dimensions is None:
frappe.flags.accounting_dimensions = frappe.get_all( frappe.flags.accounting_dimensions = frappe.get_all(
"Accounting Dimension", fields=["label", "fieldname", "disabled", "document_type"] "Accounting Dimension",
fields=["label", "fieldname", "disabled", "document_type"],
filters=filters,
) )
if as_list: if as_list:

View File

@ -22,6 +22,9 @@ class QtyMismatchError(ValidationError):
class BuyingController(StockController, Subcontracting): class BuyingController(StockController, Subcontracting):
def __setup__(self):
self.flags.ignore_permlevel_for_fields = ["buying_price_list", "price_list_currency"]
def get_feed(self): def get_feed(self):
if self.get("supplier_name"): if self.get("supplier_name"):
return _("From {0} | {1} {2}").format(self.supplier_name, self.currency, self.grand_total) return _("From {0} | {1} {2}").format(self.supplier_name, self.currency, self.grand_total)

View File

@ -16,6 +16,9 @@ from erpnext.stock.utils import get_incoming_rate
class SellingController(StockController): class SellingController(StockController):
def __setup__(self):
self.flags.ignore_permlevel_for_fields = ["selling_price_list", "price_list_currency"]
def get_feed(self): def get_feed(self):
return _("To {0} | {1} {2}").format(self.customer_name, self.currency, self.grand_total) return _("To {0} | {1} {2}").format(self.customer_name, self.currency, self.grand_total)

View File

@ -140,26 +140,6 @@ erpnext.maintenance.MaintenanceSchedule = class MaintenanceSchedule extends frap
} }
} }
start_date(doc, cdt, cdn) {
this.set_no_of_visits(doc, cdt, cdn);
}
end_date(doc, cdt, cdn) {
this.set_no_of_visits(doc, cdt, cdn);
}
periodicity(doc, cdt, cdn) {
this.set_no_of_visits(doc, cdt, cdn);
}
set_no_of_visits(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
let me = this;
if (item.start_date && item.periodicity) {
me.frm.call('validate_end_date_visits');
}
}
}; };
extend_cscript(cur_frm.cscript, new erpnext.maintenance.MaintenanceSchedule({frm: cur_frm})); extend_cscript(cur_frm.cscript, new erpnext.maintenance.MaintenanceSchedule({frm: cur_frm}));

View File

@ -213,6 +213,26 @@ class MaintenanceSchedule(TransactionBase):
if chk: if chk:
throw(_("Maintenance Schedule {0} exists against {1}").format(chk[0][0], d.sales_order)) throw(_("Maintenance Schedule {0} exists against {1}").format(chk[0][0], d.sales_order))
def validate_items_table_change(self):
doc_before_save = self.get_doc_before_save()
if not doc_before_save:
return
for prev_item, item in zip(doc_before_save.items, self.items):
fields = [
"item_code",
"start_date",
"end_date",
"periodicity",
"sales_person",
"no_of_visits",
"serial_no",
]
for field in fields:
b_doc = prev_item.as_dict()
doc = item.as_dict()
if cstr(b_doc[field]) != cstr(doc[field]):
return True
def validate_no_of_visits(self): def validate_no_of_visits(self):
return len(self.schedules) != sum(d.no_of_visits for d in self.items) return len(self.schedules) != sum(d.no_of_visits for d in self.items)
@ -221,7 +241,7 @@ class MaintenanceSchedule(TransactionBase):
self.validate_maintenance_detail() self.validate_maintenance_detail()
self.validate_dates_with_periodicity() self.validate_dates_with_periodicity()
self.validate_sales_order() self.validate_sales_order()
if not self.schedules or self.validate_no_of_visits(): if not self.schedules or self.validate_items_table_change() or self.validate_no_of_visits():
self.generate_schedule() self.generate_schedule()
def on_update(self): def on_update(self):

View File

@ -123,6 +123,36 @@ class TestMaintenanceSchedule(unittest.TestCase):
frappe.db.rollback() frappe.db.rollback()
def test_schedule_with_serials(self):
# Checks whether serials are automatically updated when changing in items table.
# Also checks if other fields trigger generate schdeule if changed in items table.
item_code = "_Test Serial Item"
make_serial_item_with_serial(item_code)
ms = make_maintenance_schedule(item_code=item_code, serial_no="TEST001, TEST002")
ms.save()
# Before Save
self.assertEqual(ms.schedules[0].serial_no, "TEST001, TEST002")
self.assertEqual(ms.schedules[0].sales_person, "Sales Team")
self.assertEqual(len(ms.schedules), 4)
self.assertFalse(ms.validate_items_table_change())
# After Save
ms.items[0].serial_no = "TEST001"
ms.items[0].sales_person = "_Test Sales Person"
ms.items[0].no_of_visits = 2
self.assertTrue(ms.validate_items_table_change())
ms.save()
self.assertEqual(ms.schedules[0].serial_no, "TEST001")
self.assertEqual(ms.schedules[0].sales_person, "_Test Sales Person")
self.assertEqual(len(ms.schedules), 2)
# When user manually deleted a row from schedules table.
ms.schedules.pop()
self.assertEqual(len(ms.schedules), 1)
ms.save()
self.assertEqual(len(ms.schedules), 2)
frappe.db.rollback()
def make_serial_item_with_serial(item_code): def make_serial_item_with_serial(item_code):
serial_item_doc = create_item(item_code, is_stock_item=1) serial_item_doc = create_item(item_code, is_stock_item=1)