def validate(self): user_branch = get_user_branch() if not _is_sys_mgr() and self.source_branch != user_branch: frappe.throw( _("Source branch only allowed to be set to User branch: {}". format(user_branch))) if self.source_branch == self.target_branch: frappe.throw(_("Source and Target Branches cannot be the same")) if not self.source_warehouse: self.source_warehouse = frappe.db.get_value( "Branch", self.source_branch, "warehouse") if not self.target_warehouse: self.target_warehouse = frappe.db.get_value( "Branch", self.target_branch, "warehouse") if not self.source_warehouse or not self.target_warehouse: frappe.throw(_("Warehouse not found for one or both Branches")) for item in self.items: has_batch_no, has_serial_no = frappe.db.get_value( "Item", item.item_code, ["has_batch_no", "has_serial_no"]) if has_batch_no and not item.batch_no: frappe.throw(_("Batch No required in row {}".format(item.idx))) if has_serial_no and len( filter(lambda x: x, item.serial_no.split("\n"))) != cint( item.qty): frappe.throw(_("Serial No missing for row {}".format( item.idx)))
def _get_branch_details(): branch = get_user_branch() if not branch: return None doc = frappe.get_doc("Branch", branch) return pick(["name", "branch_phone", "os_cr_no"], doc.as_dict()) if doc else None
def before_update_after_submit(self): if not _is_sys_mgr() and self.target_branch != get_user_branch(): frappe.throw( _("Only users from Branch: {} can perform this".format( self.target_branch))) if not self.incoming_datetime: self.incoming_datetime = now() self.validate_dates()
def get_branches(): if any(role in ["Accounts Manager"] for role in frappe.get_roles()): return split_to_list(filters.branches) user_branch = get_user_branch() if (any(role in ["Branch User", "Branch Stock"] for role in frappe.get_roles()) and user_branch): return [user_branch] frappe.throw( _("Manager privilege or Branch User / Branch Stock role required"))
def execute(): if not frappe.db.exists("Custom Field", "Customer-branch}"): return for doc in frappe.get_all( "Customer", filters=[["branch", "is", "not set"], ["old_customer_id", "is", "not set"]], fields=["name", "owner"], ): branch = get_user_branch(doc.get("owner")) if branch: frappe.db.set_value("Customer", doc.get("name"), "branch", branch)
def validate(self): user_branch = get_user_branch() if not _is_sys_mgr() and self.source_branch != user_branch: frappe.throw( _("Source branch only allowed to be set to User branch: {}". format(user_branch))) if self.source_branch == self.target_branch: frappe.throw(_("Source and Target Branches cannot be the same")) if not self.source_warehouse: self.source_warehouse = frappe.db.get_value( "Branch", self.source_branch, "warehouse") if not self.target_warehouse: self.target_warehouse = frappe.db.get_value( "Branch", self.target_branch, "warehouse") if not self.source_warehouse or not self.target_warehouse: frappe.throw(_("Warehouse not found for one or both Branches"))
def get_pos_data(): from erpnext.accounts.doctype.sales_invoice.pos import get_pos_data data = get_pos_data() allowed_items = get("bin_data", data, {}).keys() prices = _get_item_prices(allowed_items) def set_prices(item): get_price = compose(partial(get, seq=prices, default={}), partial(get, "item_code")) return merge(item, get_price(item)) trans_items = compose( partial(map, set_prices), partial(filter, lambda x: x.get("name") in allowed_items), partial(get, "items", default=[]), ) add_branch = compose( flip(merge, {"os_branch": get_user_branch()}), lambda x: x.as_dict(), partial(get, "doc", default={}), ) return merge(data, {"items": trans_items(data), "doc": add_branch(data)})
def get_warehouse(branch=None): name = branch or get_user_branch() return frappe.db.get_value("Branch", name, "warehouse") if name else None
def before_insert(doc, method): if not doc.os_branch: doc.os_branch = get_user_branch()
def before_insert(self): if not self.branch: self.branch = get_user_branch() if not self.start_time: self.start_time = now()
def get_warehouse(): branch = get_user_branch() return frappe.db.get_value("Branch", branch, "warehouse") if branch else None
def before_insert(self): if not self.branch: self.branch = get_user_branch()
def before_insert(doc, method): if not doc.branch: doc.branch = get_user_branch() doc.os_permit_sms = 1 doc.os_permit_email = 1