Exemplo n.º 1
0
    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)))
Exemplo n.º 2
0
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
Exemplo n.º 3
0
    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()
Exemplo n.º 4
0
    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"))
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
 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"))
Exemplo n.º 7
0
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)})
Exemplo n.º 8
0
def get_warehouse(branch=None):
    name = branch or get_user_branch()
    return frappe.db.get_value("Branch", name, "warehouse") if name else None
Exemplo n.º 9
0
def before_insert(doc, method):
    if not doc.os_branch:
        doc.os_branch = get_user_branch()
Exemplo n.º 10
0
 def before_insert(self):
     if not self.branch:
         self.branch = get_user_branch()
     if not self.start_time:
         self.start_time = now()
Exemplo n.º 11
0
def get_warehouse():
    branch = get_user_branch()
    return frappe.db.get_value("Branch", branch,
                               "warehouse") if branch else None
Exemplo n.º 12
0
 def before_insert(self):
     if not self.branch:
         self.branch = get_user_branch()
Exemplo n.º 13
0
def before_insert(doc, method):
    if not doc.branch:
        doc.branch = get_user_branch()

    doc.os_permit_sms = 1
    doc.os_permit_email = 1