def reconcile_against_document(args): """ Cancel JV, Update aginst document, split if required and resubmit jv """ for d in args: check_if_jv_modified(d) against_fld = { 'Journal Voucher' : 'against_jv', 'Sales Invoice' : 'against_invoice', 'Purchase Invoice' : 'against_voucher' } d['against_fld'] = against_fld[d['against_voucher_type']] # cancel JV jv_obj = frappe.get_obj('Journal Voucher', d['voucher_no'], with_children=1) jv_obj.make_gl_entries(cancel=1, adv_adj=1) # update ref in JV Detail update_against_doc(d, jv_obj) # re-submit JV jv_obj = frappe.get_obj('Journal Voucher', d['voucher_no'], with_children =1) jv_obj.make_gl_entries(cancel = 0, adv_adj =1)
def set_as_default(self): frappe.db.set_value("Global Defaults", None, "current_fiscal_year", self.doc.name) frappe.get_obj("Global Defaults").on_update() # clear cache frappe.clear_cache() msgprint(self.doc.name + _(""" is now the default Fiscal Year. \ Please refresh your browser for the change to take effect."""))
def update_birthday_reminders(self): original_stop_birthday_reminders = cint(frappe.db.get_value("HR Settings", None, "stop_birthday_reminders")) # reset birthday reminders if cint(self.doc.stop_birthday_reminders) != original_stop_birthday_reminders: frappe.db.sql("""delete from `tabEvent` where repeat_on='Every Year' and ref_type='Employee'""") if not self.doc.stop_birthday_reminders: for employee in frappe.db.sql_list("""select name from `tabEmployee` where status='Active' and ifnull(date_of_birth, '')!=''"""): frappe.get_obj("Employee", employee).update_dob_event() frappe.msgprint(frappe._("Updated Birthday Reminders"))
def update_completed_qty(bean, method): if bean.doc.doctype == "Stock Entry": material_request_map = {} for d in bean.doclist.get({"parentfield": "mtn_details"}): if d.material_request: material_request_map.setdefault(d.material_request, []).append( d.material_request_item) for mr_name, mr_items in material_request_map.items(): mr_obj = frappe.get_obj("Material Request", mr_name, with_children=1) mr_doctype = frappe.get_doctype("Material Request") if mr_obj.doc.status in ["Stopped", "Cancelled"]: frappe.throw( _("Material Request") + ": %s, " % mr_obj.doc.name + _(mr_doctype.get_label("status")) + " = %s. " % _(mr_obj.doc.status) + _("Cannot continue."), exc=frappe.InvalidStatusError) _update_requested_qty(bean, mr_obj, mr_items) # update ordered percentage and qty mr_obj.update_completed_qty(mr_items)
def update_gl_entries_after(self, warehouse_account=None): future_stock_vouchers = self.get_future_stock_vouchers() gle = self.get_voucherwise_gl_entries(future_stock_vouchers) if not warehouse_account: warehouse_account = self.get_warehouse_account() for voucher_type, voucher_no in future_stock_vouchers: existing_gle = gle.get((voucher_type, voucher_no), []) voucher_obj = frappe.get_obj(voucher_type, voucher_no) expected_gle = voucher_obj.get_gl_entries(warehouse_account) if expected_gle: matched = True if existing_gle: for entry in expected_gle: for e in existing_gle: if entry.account==e.account \ and entry.against_account==e.against_account\ and entry.cost_center==e.cost_center: if entry.debit != e.debit or entry.credit != e.credit: matched = False break else: matched = False if not matched: self.delete_gl_entries(voucher_type, voucher_no) voucher_obj.make_gl_entries(update_gl_entries_after=False) else: self.delete_gl_entries(voucher_type, voucher_no)
def set_next(current, parent, breadcrumbs): web_page = frappe.get_obj("Web Page", parent) toc_list = web_page.get_toc_list() for i, toc in enumerate(toc_list): if toc.name == current and ((i + 1) < len(toc_list)): links["next"] = toc_list[i + 1] break if not links.get("next") and breadcrumbs: set_next(parent, breadcrumbs[-1].name, breadcrumbs[:-1])
def set_new_name(self, controller=None): if self._new_name_set: # already set by bean return self._new_name_set = True self.get_meta() autoname = self._meta.autoname self.localname = self.name # amendments if self.amended_from: return self._get_amended_name() # by method else: # get my object if not controller: controller = frappe.get_obj([self]) if hasattr(controller, 'autoname'): return controller.autoname() # based on a field if autoname and autoname.startswith('field:'): n = self.fields[autoname[6:]] if not n: raise Exception, 'Name is required' self.name = n.strip() elif autoname and autoname.startswith("naming_series:"): self.set_naming_series() if not self.naming_series: frappe.msgprint(frappe._("Naming Series mandatory"), raise_exception=True) self.name = make_autoname(self.naming_series + '.#####') # call the method! elif autoname and autoname != 'Prompt': self.name = make_autoname(autoname, self.doctype) # given elif self.fields.get('__newname', ''): self.name = self.fields['__newname'] # default name for table elif self._meta.istable: self.name = make_autoname('#########', self.doctype) # unable to determine a name, use global series if not self.name: self.name = make_autoname('#########', self.doctype)
def on_submit(self): purchase_controller = frappe.get_obj("Purchase Common") self.update_prevdoc_status() self.update_bin(is_submit=1, is_stopped=0) get_obj('Authorization Control').validate_approving_authority( self.doc.doctype, self.doc.company, self.doc.grand_total) purchase_controller.update_last_purchase_rate(self, is_submit=1) frappe.db.set(self.doc, 'status', 'Submitted')
def make_controller(self): if not self.doc.doctype: raise frappe.DataError("Bean doctype not specified") if self.obj: # update doclist before running any method self.obj.doclist = self.doclist return self.obj self.obj = frappe.get_obj(doc=self.doc, doclist=self.doclist) self.obj.bean = self self.controller = self.obj return self.obj
def get_shipping_rules(party=None, quotation=None, cart_settings=None): if not party: party = get_lead_or_customer() if not quotation: quotation = _get_cart_quotation() if not cart_settings: cart_settings = frappe.get_obj("Shopping Cart Settings") # set shipping rule based on shipping territory shipping_territory = get_address_territory(quotation.doc.shipping_address_name) or \ party.territory shipping_rules = cart_settings.get_shipping_rules(shipping_territory) return shipping_rules
def apply_cart_settings(party=None, quotation=None): if not party: party = get_lead_or_customer() if not quotation: quotation = _get_cart_quotation(party) cart_settings = frappe.get_obj("Shopping Cart Settings") billing_territory = get_address_territory(quotation.doc.customer_address) or \ party.territory or "All Territories" set_price_list_and_rate(quotation, cart_settings, billing_territory) quotation.run_method("calculate_taxes_and_totals") set_taxes(quotation, cart_settings, billing_territory) _apply_shipping_rule(party, quotation, cart_settings)
def _make(doctype=None, name=None, content=None, subject=None, sent_or_received = "Sent", sender=None, recipients=None, communication_medium="Email", send_email=False, print_html=None, attachments='[]', send_me_a_copy=False, set_lead=True, date=None): # add to Communication sent_via = None # since we are using fullname and email, # if the fullname has any incompatible characters,formataddr can deal with it try: sender = json.loads(sender) except ValueError: pass if isinstance(sender, (tuple, list)) and len(sender)==2: sender = formataddr(sender) comm = frappe.new_bean('Communication') d = comm.doc d.subject = subject d.content = content d.sent_or_received = sent_or_received d.sender = sender or frappe.db.get_value("Profile", frappe.session.user, "email") d.recipients = recipients # add as child sent_via = frappe.get_obj(doctype, name) d.parent = name d.parenttype = doctype d.parentfield = "communications" if date: d.communication_date = date d.communication_medium = communication_medium comm.ignore_permissions = True comm.insert() if send_email: d = comm.doc send_comm_email(d, name, sent_via, print_html, attachments, send_me_a_copy)
def on_submit(self): purchase_controller = frappe.get_obj("Purchase Common") # Check for Approving Authority get_obj('Authorization Control').validate_approving_authority( self.doc.doctype, self.doc.company, self.doc.grand_total) # Set status as Submitted frappe.db.set(self.doc, 'status', 'Submitted') self.update_prevdoc_status() self.update_ordered_qty() self.update_stock() from erpnext.stock.doctype.serial_no.serial_no import update_serial_nos_after_submit update_serial_nos_after_submit(self, "purchase_receipt_details") purchase_controller.update_last_purchase_rate(self, 1) self.make_gl_entries()
def get_args(): obj = frappe.get_obj("About Us Settings") return { "obj": obj }