def test_staffing_plan_parent_company(self): _set_up() if dataent.db.exists("Staffing Plan", "Test"): return staffing_plan = dataent.new_doc("Staffing Plan") staffing_plan.company = "_Test Company" staffing_plan.name = "Test" staffing_plan.from_date = nowdate() staffing_plan.to_date = add_days(nowdate(), 10) staffing_plan.append( "staffing_details", { "designation": "Designer", "number_of_positions": 7, "estimated_cost_per_position": 50000 }) staffing_plan.insert() staffing_plan.submit() self.assertEqual(staffing_plan.total_estimated_budget, 350000.00) if dataent.db.exists("Staffing Plan", "Test 1"): return staffing_plan = dataent.new_doc("Staffing Plan") staffing_plan.company = "_Test Company 10" staffing_plan.name = "Test 1" staffing_plan.from_date = nowdate() staffing_plan.to_date = add_days(nowdate(), 10) staffing_plan.append( "staffing_details", { "designation": "Designer", "number_of_positions": 7, "estimated_cost_per_position": 60000 }) staffing_plan.insert() self.assertRaises(ParentCompanyError, staffing_plan.submit)
def execute(): dataent.reload_doc("accounts", "doctype", "tax_rule") customers = dataent.db.sql( """select name, default_taxes_and_charges from tabCustomer where ifnull(default_taxes_and_charges, '') != '' """, as_dict=1) for d in customers: if not dataent.db.sql( "select name from `tabTax Rule` where customer=%s", d.name): tr = dataent.new_doc("Tax Rule") tr.tax_type = "Sales" tr.customer = d.name tr.sales_tax_template = d.default_taxes_and_charges tr.save() suppliers = dataent.db.sql( """select name, default_taxes_and_charges from tabSupplier where ifnull(default_taxes_and_charges, '') != '' """, as_dict=1) for d in suppliers: if not dataent.db.sql( "select name from `tabTax Rule` where supplier=%s", d.name): tr = dataent.new_doc("Tax Rule") tr.tax_type = "Purchase" tr.supplier = d.name tr.purchase_tax_template = d.default_taxes_and_charges tr.save()
def create_plan(): if not dataent.db.exists('Subscription Plan', '_Test Plan Name'): plan = dataent.new_doc('Subscription Plan') plan.plan_name = '_Test Plan Name' plan.item = '_Test Non Stock Item' plan.price_determination = "Fixed rate" plan.cost = 900 plan.billing_interval = 'Month' plan.billing_interval_count = 1 plan.insert() if not dataent.db.exists('Subscription Plan', '_Test Plan Name 2'): plan = dataent.new_doc('Subscription Plan') plan.plan_name = '_Test Plan Name 2' plan.item = '_Test Non Stock Item' plan.price_determination = "Fixed rate" plan.cost = 1999 plan.billing_interval = 'Month' plan.billing_interval_count = 1 plan.insert() if not dataent.db.exists('Subscription Plan', '_Test Plan Name 3'): plan = dataent.new_doc('Subscription Plan') plan.plan_name = '_Test Plan Name 3' plan.item = '_Test Non Stock Item' plan.price_determination = "Fixed rate" plan.cost = 1999 plan.billing_interval = 'Day' plan.billing_interval_count = 14 plan.insert()
def get_healthcare_service_unit(): service_unit = get_random("Healthcare Service Unit", filters={"inpatient_occupancy": 1}) if not service_unit: service_unit = dataent.new_doc("Healthcare Service Unit") service_unit.healthcare_service_unit_name = "Test Service Unit Ip Occupancy" service_unit.service_unit_type = get_service_unit_type() service_unit.inpatient_occupancy = 1 service_unit.occupancy_status = "Vacant" service_unit.is_group = 0 service_unit_parent_name = dataent.db.exists({ "doctype": "Healthcare Service Unit", "healthcare_service_unit_name": "All Healthcare Service Units", "is_group": 1 }) if not service_unit_parent_name: parent_service_unit = dataent.new_doc("Healthcare Service Unit") parent_service_unit.healthcare_service_unit_name = "All Healthcare Service Units" parent_service_unit.is_group = 1 parent_service_unit.save(ignore_permissions=True) service_unit.parent_healthcare_service_unit = parent_service_unit.name else: service_unit.parent_healthcare_service_unit = service_unit_parent_name[ 0][0] service_unit.save(ignore_permissions=True) return service_unit.name return service_unit
def get_default_outgoing_email_account(raise_exception_not_set=True): '''conf should be like: { "mail_server": "smtp.example.com", "mail_port": 587, "use_tls": 1, "mail_login": "******", "mail_password": "******", "auto_email_id": "*****@*****.**", "email_sender_name": "Example Notifications", "always_use_account_email_id_as_sender": 0, "always_use_account_name_as_sender_name": 0 } ''' email_account = _get_email_account({ "enable_outgoing": 1, "default_outgoing": 1 }) if email_account: email_account.password = email_account.get_password( raise_exception=False) if not email_account and dataent.conf.get("mail_server"): # from site_config.json email_account = dataent.new_doc("Email Account") email_account.update({ "smtp_server": dataent.conf.get("mail_server"), "smtp_port": dataent.conf.get("mail_port"), # legacy: use_ssl was used in site_config instead of use_tls, but meant the same thing "use_tls": cint(dataent.conf.get("use_tls") or 0) or cint(dataent.conf.get("use_ssl") or 0), "login_id": dataent.conf.get("mail_login"), "email_id": dataent.conf.get("auto_email_id") or dataent.conf.get("mail_login") or '*****@*****.**', "password": dataent.conf.get("mail_password"), "always_use_account_email_id_as_sender": dataent.conf.get("always_use_account_email_id_as_sender", 0), "always_use_account_name_as_sender_name": dataent.conf.get("always_use_account_name_as_sender_name", 0) }) email_account.from_site_config = True email_account.name = dataent.conf.get("email_sender_name") or "Dataent" if not email_account and not raise_exception_not_set: return None if dataent.are_emails_muted(): # create a stub email_account = dataent.new_doc("Email Account") email_account.update({"email_id": "*****@*****.**"}) return email_account
def get_party(user=None): if not user: user = dataent.session.user contact_name = dataent.db.get_value("Contact", {"email_id": user}) party = None if contact_name: contact = dataent.get_doc('Contact', contact_name) if contact.links: party_doctype = contact.links[0].link_doctype party = contact.links[0].link_name cart_settings = dataent.get_doc("Shopping Cart Settings") debtors_account = '' if cart_settings.enable_checkout: debtors_account = get_debtors_account(cart_settings) if party: return dataent.get_doc(party_doctype, party) else: if not cart_settings.enabled: dataent.local.flags.redirect_location = "/contact" raise dataent.Redirect customer = dataent.new_doc("Customer") fullname = get_fullname(user) customer.update({ "customer_name": fullname, "customer_type": "Individual", "customer_group": get_shopping_cart_settings().default_customer_group, "territory": get_root_of("Territory") }) if debtors_account: customer.update({ "accounts": [{ "company": cart_settings.company, "account": debtors_account }] }) customer.flags.ignore_mandatory = True customer.insert(ignore_permissions=True) contact = dataent.new_doc("Contact") contact.update({ "first_name": fullname, "email_id": user }) contact.append('links', dict(link_doctype='Customer', link_name=customer.name)) contact.flags.ignore_mandatory = True contact.insert(ignore_permissions=True) return customer
def test_fee_validity(self): dataent.db.sql("""delete from `tabPatient Appointment`""") dataent.db.sql("""delete from `tabFee Validity`""") patient = get_random("Patient") practitioner = get_random("Healthcare Practitioner") department = get_random("Medical Department") if not patient: patient = dataent.new_doc("Patient") patient.patient_name = "_Test Patient" patient.sex = "Male" patient.save(ignore_permissions=True) patient = patient.name if not department: medical_department = dataent.new_doc("Medical Department") medical_department.department = "_Test Medical Department" medical_department.save(ignore_permissions=True) department = medical_department.name if not practitioner: practitioner = dataent.new_doc("Healthcare Practitioner") practitioner.first_name = "_Test Healthcare Practitioner" practitioner.department = department practitioner.save(ignore_permissions=True) practitioner = practitioner.name dataent.db.set_value("Healthcare Settings", None, "max_visit", 2) dataent.db.set_value("Healthcare Settings", None, "valid_days", 7) appointment = create_appointment(patient, practitioner, nowdate(), department) invoiced = dataent.db.get_value("Patient Appointment", appointment.name, "invoiced") self.assertEqual(invoiced, 0) invoice_appointment(appointment) appointment = create_appointment(patient, practitioner, add_days(nowdate(), 4), department) invoiced = dataent.db.get_value("Patient Appointment", appointment.name, "invoiced") self.assertTrue(invoiced) appointment = create_appointment(patient, practitioner, add_days(nowdate(), 5), department) invoiced = dataent.db.get_value("Patient Appointment", appointment.name, "invoiced") self.assertEqual(invoiced, 0) appointment = create_appointment(patient, practitioner, add_days(nowdate(), 10), department) invoiced = dataent.db.get_value("Patient Appointment", appointment.name, "invoiced") self.assertEqual(invoiced, 0)
def link_customer_and_address(raw_billing_data,customer_status): if customer_status == 0: # create customer = dataent.new_doc("Customer") address = dataent.new_doc("Address") if customer_status == 1: # Edit customer_woo_com_email = raw_billing_data.get("email") customer = dataent.get_doc("Customer",{"woocommerce_email": customer_woo_com_email}) old_name = customer.customer_name full_name = str(raw_billing_data.get("first_name"))+ " "+str(raw_billing_data.get("last_name")) customer.customer_name = full_name customer.woocommerce_email = str(raw_billing_data.get("email")) customer.save() dataent.db.commit() if customer_status == 1: dataent.rename_doc("Customer", old_name, full_name) address = dataent.get_doc("Address",{"woocommerce_email":customer_woo_com_email}) customer = dataent.get_doc("Customer",{"woocommerce_email": customer_woo_com_email}) address.address_line1 = raw_billing_data.get("address_1", "Not Provided") address.address_line2 = raw_billing_data.get("address_2", "Not Provided") address.city = raw_billing_data.get("city", "Not Provided") address.woocommerce_email = str(raw_billing_data.get("email")) address.address_type = "Shipping" address.country = dataent.get_value("Country", filters={"code":raw_billing_data.get("country", "IN").lower()}) address.state = raw_billing_data.get("state") address.pincode = str(raw_billing_data.get("postcode")) address.phone = str(raw_billing_data.get("phone")) address.email_id = str(raw_billing_data.get("email")) address.append("links", { "link_doctype": "Customer", "link_name": customer.customer_name }) address.save() dataent.db.commit() if customer_status == 1: address = dataent.get_doc("Address",{"woocommerce_email":customer_woo_com_email}) old_address_title = address.name new_address_title = customer.customer_name+"-billing" address.address_title = customer.customer_name address.save() dataent.rename_doc("Address",old_address_title,new_address_title) dataent.db.commit()
def test_production_plan_sales_orders(self): item = 'Test Production Item 1' so = make_sales_order(item_code=item, qty=5) sales_order = so.name sales_order_item = so.items[0].name pln = dataent.new_doc('Production Plan') pln.company = so.company pln.get_items_from = 'Sales Order' pln.append( 'sales_orders', { 'sales_order': so.name, 'sales_order_date': so.transaction_date, 'customer': so.customer, 'grand_total': so.grand_total }) pln.get_so_items() pln.submit() pln.make_work_order() work_order = dataent.db.get_value( 'Work Order', { 'sales_order': sales_order, 'production_plan': pln.name, 'sales_order_item': sales_order_item }, 'name') wo_doc = dataent.get_doc('Work Order', work_order) wo_doc.update({ 'wip_warehouse': '_Test Warehouse 1 - _TC', 'fg_warehouse': '_Test Warehouse - _TC' }) wo_doc.submit() so_wo_qty = dataent.db.get_value('Sales Order Item', sales_order_item, 'work_order_qty') self.assertTrue(so_wo_qty, 5) pln = dataent.new_doc('Production Plan') pln.update({ 'from_date': so.transaction_date, 'to_date': so.transaction_date, 'customer': so.customer, 'item_code': item }) sales_orders = get_sales_orders(pln) or {} sales_orders = [ d.get('name') for d in sales_orders if d.get('name') == sales_order ] self.assertEqual(sales_orders, [])
def _set_defaults(self): if dataent.flags.in_import: return new_doc = dataent.new_doc(self.doctype, as_dict=True) self.update_if_missing(new_doc) # children for df in self.meta.get_table_fields(): new_doc = dataent.new_doc(df.options, as_dict=True) value = self.get(df.fieldname) if isinstance(value, list): for d in value: d.update_if_missing(new_doc)
def make_opportunity(buyer_name, email_id): buyer_name = "HUB-" + buyer_name if not dataent.db.exists('Lead', {'email_id': email_id}): lead = dataent.new_doc("Lead") lead.lead_name = buyer_name lead.email_id = email_id lead.save(ignore_permissions=True) o = dataent.new_doc("Opportunity") o.opportunity_from = "Lead" o.lead = dataent.get_all("Lead", filters={"email_id": email_id}, fields=["name"])[0]["name"] o.save(ignore_permissions=True)
def test_status_goes_back_to_active_after_invoice_is_paid(self): subscription = dataent.new_doc('Subscription') subscription.customer = '_Test Customer' subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1}) subscription.start = '2018-01-01' subscription.insert() subscription.process() # generate first invoice self.assertEqual(len(subscription.invoices), 1) self.assertEqual(subscription.status, 'Past Due Date') subscription.get_current_invoice() current_invoice = subscription.get_current_invoice() self.assertIsNotNone(current_invoice) current_invoice.db_set('outstanding_amount', 0) current_invoice.db_set('status', 'Paid') subscription.process() self.assertEqual(subscription.status, 'Active') self.assertEqual(subscription.current_invoice_start, add_months(subscription.start, 1)) self.assertEqual(len(subscription.invoices), 1) subscription.delete()
def create_quotation(self): quotation = dataent.new_doc("Quotation") values = { "doctype": "Quotation", "quotation_to": "Customer", "order_type": "Shopping Cart", "party_name": get_party(dataent.session.user).name, "docstatus": 0, "contact_email": dataent.session.user, "selling_price_list": "_Test Price List Rest of the World", "currency": "USD", "taxes_and_charges" : "_Test Tax 1 - _TC", "conversion_rate":1, "transaction_date" : nowdate(), "valid_till" : add_months(nowdate(), 1), "items": [{ "item_code": "_Test Item", "qty": 1 }], "taxes": dataent.get_doc("Sales Taxes and Charges Template", "_Test Tax 1 - _TC").taxes, "company": "_Test Company" } quotation.update(values) quotation.insert(ignore_permissions=True) return quotation
def make_fee_records(self): from epaas.education.api import get_fee_components fee_list = [] for d in self.fees: fee_components = get_fee_components(d.fee_structure) if fee_components: fees = dataent.new_doc("Fees") fees.update({ "student": self.student, "academic_year": self.academic_year, "academic_term": d.academic_term, "fee_structure": d.fee_structure, "program": self.program, "due_date": d.due_date, "student_name": self.student_name, "program_enrollment": self.name, "components": fee_components }) fees.save() fees.submit() fee_list.append(fees.name) if fee_list: fee_list = ["""<a href="#Form/Fees/%s" target="_blank">%s</a>""" % \ (fee, fee) for fee in fee_list] msgprint(_("Fee Records Created - {0}").format(comma_and(fee_list)))
def make_material_request(item_code, qty): mr = dataent.new_doc("Material Request") variant_of = dataent.db.get_value('Item', item_code, 'variant_of') or item_code if dataent.db.get_value('BOM', { 'item': variant_of, 'is_default': 1, 'is_active': 1 }): mr.material_request_type = 'Manufacture' else: mr.material_request_type = "Purchase" mr.transaction_date = dataent.flags.current_date mr.schedule_date = dataent.utils.add_days(mr.transaction_date, 7) mr.append( "items", { "doctype": "Material Request Item", "schedule_date": dataent.utils.add_days(mr.transaction_date, 7), "item_code": item_code, "qty": qty }) mr.insert() mr.submit() return mr
def test_subscription_unpaid_back_to_active(self): settings = dataent.get_single('Subscription Settings') default_grace_period_action = settings.cancel_after_grace settings.cancel_after_grace = 0 settings.save() subscription = dataent.new_doc('Subscription') subscription.customer = '_Test Customer' subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1}) subscription.start = '2018-01-01' subscription.insert() subscription.process() # generate first invoice self.assertEqual(subscription.status, 'Past Due Date') subscription.process() # This should change status to Cancelled since grace period is 0 self.assertEqual(subscription.status, 'Unpaid') invoice = subscription.get_current_invoice() invoice.db_set('outstanding_amount', 0) invoice.db_set('status', 'Paid') subscription.process() self.assertEqual(subscription.status, 'Active') # A new invoice is generated subscription.process() self.assertEqual(subscription.status, 'Past Due Date') settings.cancel_after_grace = default_grace_period_action settings.save() subscription.delete()
def test_subscription_cancellation_invoices_with_prorata_true(self): settings = dataent.get_single('Subscription Settings') to_prorate = settings.prorate settings.prorate = 1 settings.save() subscription = dataent.new_doc('Subscription') subscription.customer = '_Test Customer' subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1}) subscription.save() subscription.cancel_subscription() invoice = subscription.get_current_invoice() diff = flt( date_diff(nowdate(), subscription.current_invoice_start) + 1) plan_days = flt( date_diff(subscription.current_invoice_end, subscription.current_invoice_start) + 1) prorate_factor = flt(diff / plan_days) self.assertEqual(flt(invoice.grand_total, 2), flt(prorate_factor * 900, 2)) settings.prorate = to_prorate settings.save() subscription.delete()
def test_subscription_is_past_due_doesnt_change_within_grace_period(self): settings = dataent.get_single('Subscription Settings') grace_period = settings.grace_period settings.grace_period = 1000 settings.save() subscription = dataent.new_doc('Subscription') subscription.customer = '_Test Customer' subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1}) subscription.start = '2018-01-01' subscription.insert() subscription.process() # generate first invoice self.assertEqual(subscription.status, 'Past Due Date') subscription.process() # Grace period is 1000 days so status should remain as Past Due Date self.assertEqual(subscription.status, 'Past Due Date') subscription.process() self.assertEqual(subscription.status, 'Past Due Date') subscription.process() self.assertEqual(subscription.status, 'Past Due Date') settings.grace_period = grace_period settings.save() subscription.delete()
def test_subscription_remains_active_during_invoice_period(self): subscription = dataent.new_doc('Subscription') subscription.customer = '_Test Customer' subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1}) subscription.save() subscription.process() # no changes expected self.assertEqual(subscription.status, 'Active') self.assertEqual(subscription.current_invoice_start, nowdate()) self.assertEqual(subscription.current_invoice_end, add_to_date(nowdate(), months=1, days=-1)) self.assertEqual(len(subscription.invoices), 0) subscription.process() # no changes expected still self.assertEqual(subscription.status, 'Active') self.assertEqual(subscription.current_invoice_start, nowdate()) self.assertEqual(subscription.current_invoice_end, add_to_date(nowdate(), months=1, days=-1)) self.assertEqual(len(subscription.invoices), 0) subscription.process() # no changes expected yet still self.assertEqual(subscription.status, 'Active') self.assertEqual(subscription.current_invoice_start, nowdate()) self.assertEqual(subscription.current_invoice_end, add_to_date(nowdate(), months=1, days=-1)) self.assertEqual(len(subscription.invoices), 0) subscription.delete()
def make_depreciation_entry(self): asset = dataent.get_doc("Asset", self.asset) fixed_asset_account, accumulated_depreciation_account, depreciation_expense_account = \ get_depreciation_accounts(asset) depreciation_cost_center, depreciation_series = dataent.get_cached_value( 'Company', asset.company, ["depreciation_cost_center", "series_for_depreciation_entry"]) je = dataent.new_doc("Journal Entry") je.voucher_type = "Depreciation Entry" je.naming_series = depreciation_series je.posting_date = self.date je.company = self.company je.remark = "Depreciation Entry against {0} worth {1}".format( self.asset, self.difference_amount) je.append( "accounts", { "account": accumulated_depreciation_account, "credit_in_account_currency": self.difference_amount, "cost_center": depreciation_cost_center or self.cost_center }) je.append( "accounts", { "account": depreciation_expense_account, "debit_in_account_currency": self.difference_amount, "cost_center": depreciation_cost_center or self.cost_center }) je.flags.ignore_permissions = True je.submit() self.db_set("journal_entry", je.name)
def test_subcription_cancellation_and_process(self): settings = dataent.get_single('Subscription Settings') default_grace_period_action = settings.cancel_after_grace settings.cancel_after_grace = 1 settings.save() subscription = dataent.new_doc('Subscription') subscription.customer = '_Test Customer' subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1}) subscription.start = '2018-01-01' subscription.insert() subscription.process() # generate first invoice invoices = len(subscription.invoices) self.assertEqual(subscription.status, 'Past Due Date') self.assertEqual(len(subscription.invoices), invoices) subscription.cancel_subscription() self.assertEqual(subscription.status, 'Cancelled') self.assertEqual(len(subscription.invoices), invoices) subscription.process() self.assertEqual(subscription.status, 'Cancelled') self.assertEqual(len(subscription.invoices), invoices) subscription.process() self.assertEqual(subscription.status, 'Cancelled') self.assertEqual(len(subscription.invoices), invoices) settings.cancel_after_grace = default_grace_period_action settings.save() subscription.delete()
def test_rename_account(self): if not dataent.db.exists("Account", "1210 - Debtors - _TC"): acc = dataent.new_doc("Account") acc.account_name = "Debtors" acc.parent_account = "Accounts Receivable - _TC" acc.account_number = "1210" acc.company = "_Test Company" acc.insert() account_number, account_name = dataent.db.get_value( "Account", "1210 - Debtors - _TC", ["account_number", "account_name"]) self.assertEqual(account_number, "1210") self.assertEqual(account_name, "Debtors") new_account_number = "1211-11-4 - 6 - " new_account_name = "Debtors 1 - Test - " update_account_number("1210 - Debtors - _TC", new_account_name, new_account_number) new_acc = dataent.db.get_value( "Account", "1211-11-4 - 6 - - Debtors 1 - Test - - _TC", ["account_name", "account_number"], as_dict=1) self.assertEqual(new_acc.account_name, "Debtors 1 - Test -") self.assertEqual(new_acc.account_number, "1211-11-4 - 6 -") dataent.delete_doc("Account", "1211-11-4 - 6 - Debtors 1 - Test - - _TC")
def test_prepaid_subscriptions_with_prorate_true(self): settings = dataent.get_single('Subscription Settings') to_prorate = settings.prorate settings.prorate = 1 settings.save() subscription = dataent.new_doc('Subscription') subscription.customer = '_Test Customer' subscription.generate_invoice_at_period_start = True subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1}) subscription.save() subscription.cancel_subscription() self.assertEqual(len(subscription.invoices), 1) current_inv = subscription.get_current_invoice() self.assertEqual(current_inv.status, "Unpaid") diff = flt( date_diff(nowdate(), subscription.current_invoice_start) + 1) plan_days = flt( date_diff(subscription.current_invoice_end, subscription.current_invoice_start) + 1) prorate_factor = flt(diff / plan_days) self.assertEqual(flt(current_inv.grand_total, 2), flt(prorate_factor * 900, 2)) settings.prorate = to_prorate settings.save() subscription.delete()
def create_translation(key, val): translation = dataent.new_doc('Translation') translation.language = key translation.source_name = val[0] translation.target_name = val[1] translation.save() return translation
def setup_services(): for service in [{"old_name": "Razorpay", "new_name": "Razorpay"}, {"old_name": "PayPal", "new_name": "PayPal"}, {"old_name": "Dropbox Integration", "new_name": "Dropbox"}, {"old_name": "LDAP Auth", "new_name": "LDAP"}]: try: service_doc = dataent.get_doc("Integration Service", service["old_name"]) settings = json.loads(service_doc.custom_settings_json) service_settings = dataent.new_doc("{0} Settings".format(service["new_name"])) service_settings.update(settings) service_settings.flags.ignore_mandatory = True service_settings.save(ignore_permissions=True) if service["old_name"] in ["Dropbox Integration", "LDAP Auth"]: delete_doc("Integration Service", service["old_name"]) new_service_doc = dataent.get_doc({ "doctype": "Integration Service", "service": service["new_name"], "enabled": 1 }) new_service_doc.flags.ignore_mandatory = True new_service_doc.save(ignore_permissions=True) except Exception: pass
def _create_account(args): if args["parent_account"] and dataent.db.exists( "Account", args["parent_account"]): account_id = dataent.db.get_value( "Account", { "account_name": args["account_name"], "company": args["company"] }) if not account_id: account = dataent.new_doc("Account") account.is_group = 0 account.update(args) account.insert() account_id = account.name dataent.db.set_value( "Company", args["company"], ("default_receivable_account" if args["account_type"] == "Receivable" else "default_payable_account"), account_id) receivable_payable_accounts.setdefault(args["company"], {}).setdefault( args["account_type"], account_id)
def make_template(payment_term): doc = dataent.new_doc('Payment Terms Template Detail') doc.payment_term = payment_term.payment_term_name doc.due_date_based_on = payment_term.due_date_based_on doc.invoice_portion = payment_term.invoice_portion doc.description = payment_term.description doc.credit_days = payment_term.credit_days doc.credit_months = payment_term.credit_months template = dataent.new_doc('Payment Terms Template') template.template_name = 'Default Payment Term - {0}'.format( payment_term.payment_term_name) template.append('terms', doc) template.save() return template
def make_jv_entry(loan, company, loan_account, applicant_type, applicant, loan_amount, payment_account=None): journal_entry = dataent.new_doc('Journal Entry') journal_entry.voucher_type = 'Bank Entry' journal_entry.user_remark = _('Against Loan: {0}').format(loan) journal_entry.company = company journal_entry.posting_date = nowdate() account_amt_list = [] account_amt_list.append({ "account": loan_account, "debit_in_account_currency": loan_amount, "party_type": applicant_type, "party": applicant, "reference_type": "Loan", "reference_name": loan, }) account_amt_list.append({ "account": payment_account, "credit_in_account_currency": loan_amount, "reference_type": "Loan", "reference_name": loan, }) journal_entry.set("accounts", account_amt_list) return journal_entry.as_dict()
def allocate_leave(self): self.validate_values() leave_allocated_for = [] employees = self.get_employees() if not employees: dataent.throw(_("No employee found")) for d in self.get_employees(): try: la = dataent.new_doc('Leave Allocation') la.set("__islocal", 1) la.employee = cstr(d[0]) la.employee_name = dataent.db.get_value( 'Employee', cstr(d[0]), 'employee_name') la.leave_type = self.leave_type la.from_date = self.from_date la.to_date = self.to_date la.carry_forward = cint(self.carry_forward) la.new_leaves_allocated = flt(self.no_of_days) la.docstatus = 1 la.save() leave_allocated_for.append(d[0]) except: pass if leave_allocated_for: msgprint( _("Leaves Allocated Successfully for {0}").format( comma_and(leave_allocated_for)))
def make_jv_entry(self): self.check_permission('write') journal_entry = dataent.new_doc('Journal Entry') journal_entry.voucher_type = 'Bank Entry' journal_entry.user_remark = _('Against Loan: {0}').format(self.name) journal_entry.company = self.company journal_entry.posting_date = nowdate() account_amt_list = [] account_amt_list.append({ "account": self.loan_account, "party_type": self.applicant_type, "party": self.applicant, "debit_in_account_currency": self.loan_amount, "reference_type": "Loan", "reference_name": self.name, }) account_amt_list.append({ "account": self.payment_account, "credit_in_account_currency": self.loan_amount, "reference_type": "Loan", "reference_name": self.name, }) journal_entry.set("accounts", account_amt_list) return journal_entry.as_dict()