def set_missing_values(self, for_validate=False): if not self.credit_to: self.credit_to = get_party_account(self.company, self.supplier, "Supplier") if not self.due_date: self.due_date = get_due_date(self.posting_date, "Supplier", self.supplier, self.company) super(PurchaseInvoice, self).set_missing_values(for_validate)
def set_missing_values(self, for_validate=False): if not self.credit_to: self.credit_to = get_party_account(self.company, self.supplier, "Supplier") if not self.due_date: self.due_date = get_due_date(self.posting_date, self.supplier, "Supplier", self.credit_to, self.company) super(PurchaseInvoice, self).set_missing_values(for_validate)
def set_missing_values(self, for_validate=False): if not self.credit_to: self.credit_to = get_party_account("Supplier", self.supplier, self.company) self.party_account_currency = frappe.db.get_value("Account", self.credit_to, "account_currency", cache=True) if not self.due_date: self.due_date = get_due_date(self.posting_date, "Supplier", self.supplier, self.company, self.bill_date) super(PurchaseInvoice, self).set_missing_values(for_validate)
def set_missing_values(self, for_validate=False): if not self.credit_to: self.credit_to = get_party_account("Supplier", self.supplier, self.company) self.party_account_currency = frappe.db.get_value("Account", self.credit_to, "account_currency", cache=True) if not self.due_date: self.due_date = get_due_date(self.posting_date, "Supplier", self.supplier, self.company, self.bill_date) super(PurchasingInvoice, self).set_missing_values(for_validate)
def set_missing_values(self, for_validate=False): self.set_pos_fields(for_validate) if not self.debit_to: self.debit_to = get_party_account(self.company, self.customer, "Customer") if not self.due_date and self.customer: self.due_date = get_due_date(self.posting_date, "Customer", self.customer, self.company) super(SalesInvoice, self).set_missing_values(for_validate)
def set_missing_values(self, for_validate=False): self.set_pos_fields(for_validate) if not self.debit_to: self.debit_to = get_party_account(self.company, self.customer, "Customer") if not self.due_date: self.due_date = get_due_date(self.posting_date, "Customer", self.customer, self.company) super(SalesInvoice, self).set_missing_values(for_validate)
def test_supplier_default_payment_terms(self): # Payment Term based on Days after invoice date frappe.db.set_value( "Supplier", "_Test Supplier With Template 1", "payment_terms", "_Test Payment Term Template 3") due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1") self.assertEqual(due_date, "2016-02-21") due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier With Template 1") self.assertEqual(due_date, "2017-02-21") # Payment Term based on last day of month frappe.db.set_value( "Supplier", "_Test Supplier With Template 1", "payment_terms", "_Test Payment Term Template 1") due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1") self.assertEqual(due_date, "2016-02-29") due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier With Template 1") self.assertEqual(due_date, "2017-02-28") frappe.db.set_value("Supplier", "_Test Supplier With Template 1", "payment_terms", "") # Set credit limit for the supplier group instead of supplier and evaluate the due date frappe.db.set_value("Supplier Group", "_Test Supplier Group", "payment_terms", "_Test Payment Term Template 3") due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1") self.assertEqual(due_date, "2016-02-21") # Payment terms for Supplier Group instead of supplier and evaluate the due date frappe.db.set_value("Supplier Group", "_Test Supplier Group", "payment_terms", "_Test Payment Term Template 1") # Leap year due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1") self.assertEqual(due_date, "2016-02-29") # # Non Leap year due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier With Template 1") self.assertEqual(due_date, "2017-02-28") # Supplier with no default Payment Terms Template frappe.db.set_value("Supplier Group", "_Test Supplier Group", "payment_terms", "") frappe.db.set_value("Supplier", "_Test Supplier", "payment_terms", "") due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier") self.assertEqual(due_date, "2016-01-22") # # Non Leap year due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier") self.assertEqual(due_date, "2017-01-22")
def set_missing_values(self, for_validate=False): pos = self.set_pos_fields(for_validate) if not self.debit_to: self.debit_to = get_party_account("Customer", self.customer, self.company) if not self.due_date and self.customer: self.due_date = get_due_date(self.posting_date, "Customer", self.customer, self.company) super(SalesInvoice, self).set_missing_values(for_validate) if pos: return {"print_format": pos.get("print_format") }
def test_customer_payment_terms(self): frappe.db.set_value("Customer", "_Test Customer With Template", "payment_terms", "_Test Payment Term Template 3") due_date = get_due_date("2016-01-22", "Customer", "_Test Customer With Template") self.assertEqual(due_date, "2016-02-21") due_date = get_due_date("2017-01-22", "Customer", "_Test Customer With Template") self.assertEqual(due_date, "2017-02-21") frappe.db.set_value("Customer", "_Test Customer With Template", "payment_terms", "_Test Payment Term Template 1") due_date = get_due_date("2016-01-22", "Customer", "_Test Customer With Template") self.assertEqual(due_date, "2016-02-29") due_date = get_due_date("2017-01-22", "Customer", "_Test Customer With Template") self.assertEqual(due_date, "2017-02-28") frappe.db.set_value("Customer", "_Test Customer With Template", "payment_terms", "") # No default payment term template attached due_date = get_due_date("2016-01-22", "Customer", "_Test Customer") self.assertEqual(due_date, "2016-01-22") due_date = get_due_date("2017-01-22", "Customer", "_Test Customer") self.assertEqual(due_date, "2017-01-22")
def test_customer_payment_terms(self): frappe.db.set_value( "Customer", "_Test Customer With Template", "payment_terms", "_Test Payment Term Template 3") due_date = get_due_date("2016-01-22", "Customer", "_Test Customer With Template") self.assertEqual(due_date, "2016-02-21") due_date = get_due_date("2017-01-22", "Customer", "_Test Customer With Template") self.assertEqual(due_date, "2017-02-21") frappe.db.set_value( "Customer", "_Test Customer With Template", "payment_terms", "_Test Payment Term Template 1") due_date = get_due_date("2016-01-22", "Customer", "_Test Customer With Template") self.assertEqual(due_date, "2016-02-29") due_date = get_due_date("2017-01-22", "Customer", "_Test Customer With Template") self.assertEqual(due_date, "2017-02-28") frappe.db.set_value("Customer", "_Test Customer With Template", "payment_terms", "") # No default payment term template attached due_date = get_due_date("2016-01-22", "Customer", "_Test Customer") self.assertEqual(due_date, "2016-01-22") due_date = get_due_date("2017-01-22", "Customer", "_Test Customer") self.assertEqual(due_date, "2017-01-22")
def update_payment_due_date(sales_invoice): invoice = frappe.get_doc("Sales Invoice", sales_invoice) if not invoice.payment_terms_template: return due_date = get_due_date(invoice.posting_date, "Customer", invoice.customer, bill_date=frappe.utils.add_days(nowdate(), 7)) # Update due date in both parent and child documents invoice.due_date = due_date for term in invoice.payment_schedule: term.due_date = due_date invoice.save()
def set_missing_values(self, for_validate=False): if not self.credit_to: self.credit_to = get_party_account("Supplier", self.supplier, self.company) self.party_account_currency = frappe.db.get_value("Account", self.credit_to, "account_currency", cache=True) if not self.due_date: self.due_date = get_due_date(self.posting_date, "Supplier", self.supplier, self.company, self.bill_date) tds_category = frappe.db.get_value("Supplier", self.supplier, "tax_withholding_category") if tds_category and not for_validate: self.apply_tds = 1 self.tax_withholding_category = tds_category super(PurchaseInvoice, self).set_missing_values(for_validate)
def test_supplier_due_date_against_supplier_credit_limit(self): # Set Credit Limit based on Fixed days frappe.db.set_value("Supplier", "_Test Supplier", "credit_days_based_on", "Fixed Days") frappe.db.set_value("Supplier", "_Test Supplier", "credit_days", 10) due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier", "_Test Company") self.assertEqual(due_date, "2016-02-01") # Set Credit Limit based on Last day next month frappe.db.set_value("Supplier", "_Test Supplier", "credit_days", 0) frappe.db.set_value("Supplier", "_Test Supplier", "credit_days_based_on", "Last Day of the Next Month") # Leap year due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier", "_Test Company") self.assertEqual(due_date, "2016-02-29") # Non Leap year due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier", "_Test Company") self.assertEqual(due_date, "2017-02-28") frappe.db.set_value("Supplier", "_Test Supplier", "credit_days_based_on", "") # Set credit limit for the supplier type instead of supplier and evaluate the due date # based on Fixed days frappe.db.set_value("Supplier Type", "_Test Supplier Type", "credit_days_based_on", "Fixed Days") frappe.db.set_value("Supplier Type", "_Test Supplier Type", "credit_days", 10) due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier", "_Test Company") self.assertEqual(due_date, "2016-02-01") # Set credit limit for the supplier type instead of supplier and evaluate the due date # based on Last day of next month frappe.db.set_value("Supplier", "_Test Supplier Type", "credit_days", 0) frappe.db.set_value("Supplier Type", "_Test Supplier Type", "credit_days_based_on", "Last Day of the Next Month") # Leap year due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier", "_Test Company") self.assertEqual(due_date, "2016-02-29") # Non Leap year due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier", "_Test Company") self.assertEqual(due_date, "2017-02-28")
def set_missing_values(self, for_validate=False): profile = self.set_pos_fields(for_validate) if not self.debit_to: self.debit_to = get_party_account("Customer", self.customer, self.company) self.party_account_currency = frappe.db.get_value("Account", self.debit_to, "account_currency", cache=True) if not self.due_date and self.customer: self.due_date = get_due_date(self.posting_date, "Customer", self.customer, self.company) super(SalesInvoice, self).set_missing_values(for_validate) print_format = profile.get("print_format") if profile else None if not print_format and not cint(frappe.db.get_value('Print Format', 'POS Invoice', 'disabled')): print_format = 'POS Invoice' if profile: return { "print_format": print_format, "campaign": profile.get("campaign"), "allow_print_before_pay": profile.get("allow_print_before_pay") }
def selco_purchase_invoice_validate(doc,method): #doc.posting_date = doc.supplier_invoice_date doc.bill_no = doc.supplier_invoice_number doc.due_date = get_due_date(doc.supplier_invoice_date, "Supplier", doc.supplier, doc.company)
def selco_purchase_invoice_validate(doc, method): from erpnext.accounts.party import get_due_date doc.due_date = get_due_date(doc.selco_supplier_invoice_date, "Supplier", doc.supplier)
def generate(self): bill = frappe.db.sql( """SELECT u.customer as customer, u.name as unit FROM `tabUnit` u WHERE u.name IN (SELECT parent FROM `tabUnit Charge`); """, as_dict=1) for i in bill: if i.customer and self.company and self.date: doc = frappe.new_doc("Sales Invoice") doc.customer = i.customer "doc.series = self.series" doc.posting_date = self.date "doc.due_date = self.date" doc.company = self.company if not doc.due_date and doc.customer: doc.due_date = get_due_date(doc.posting_date, "Customer", doc.customer) if not doc.debit_to: doc.debit_to = get_party_account("Customer", doc.customer, doc.company) doc.remarks = 'Billing for ' + i.unit + ' for the period ' + self.bill_period doc.set_missing_values(False) "Add Fixed Amounts" item = frappe.db.sql( """SELECT c.item as item, c.description as description, uc.rate as rate FROM `tabUnit Charge` uc,`tabCharge` c WHERE uc.charge = c.name AND c.charge_type = 'Fixed Amount' AND uc.bill_run_type = %s AND uc.parent = %s;""", (self.bill_run_type, i.unit), as_dict=1) for j in item: c_doc = doc.append( 'items', { "item_code": j.item, "item_name": j.description, "description": j.description, "qty": 1, "rate": j.rate, "amount": j.rate }) "Add Meter Based Charges" mitem = frappe.db.sql( """SELECT c.item, c.description, mr.usage as qty, r.rate_per_kwh as rate FROM `tabUnit Charge` uc, `tabMain Meter` m, `tabMeter Reading` r, `tabCharge` c, `tabUnit Meter Reading` mr WHERE uc.charge = c.name AND c.charge_type = 'Meter' AND uc.bill_run_type = %s AND uc.parent = %s AND r.bill_period = %s AND r.name = mr.parent AND r.main_meter = m.name AND r.docstatus = 1 AND uc.name = mr.unit_charge;""", (self.bill_run_type, i.unit, self.bill_period), as_dict=1) for m in mitem: m_doc = doc.append( 'items', { "item_code": m.item, "item_name": m.description, "description": m.description, "qty": m.qty, "rate": m.rate, "amount": m.rate * m.qty }) "Add Unit Size Based Charges" sitem = frappe.db.sql( """SELECT c.item as item, c.description as description, u.unit_size as qty, uc.rate as rate FROM `tabUnit Charge` uc,`tabCharge` c, `tabUnit` u WHERE uc.charge = c.name AND u.name = uc.parent AND c.charge_type = 'Unit Size' AND uc.bill_run_type = %s AND uc.parent = %s;""", (self.bill_run_type, i.unit), as_dict=1) for s in sitem: m_doc = doc.append( 'items', { "item_code": s.item, "item_name": s.description, "description": s.description, "qty": s.qty, "rate": s.rate, "amount": s.rate * s.qty }) "Add Head Count Based Charges" sitem = frappe.db.sql( """SELECT c.item as item, c.description as description, u.head_count as qty, uc.rate as rate FROM `tabUnit Charge` uc,`tabCharge` c, `tabUnit` u WHERE uc.charge = c.name AND u.name = uc.parent AND c.charge_type = 'Head Count' AND uc.bill_run_type = %s AND uc.parent = %s;""", (self.bill_run_type, i.unit), as_dict=1) for s in sitem: m_doc = doc.append( 'items', { "item_code": s.item, "item_name": s.description, "description": s.description, "qty": s.qty, "rate": s.rate, "amount": s.rate * s.qty }) "Add Manual Charges" sitem = frappe.db.sql( """SELECT c.item as item, c.description as description, ci.quantity as qty, ci.rate as rate FROM `tabOther Charges` uc,`tabCharge` c, `tabUnit` u, `tabOther Charges Items` ci WHERE uc.unit = u.name AND ci.parent = uc.name AND ci.charge = c.name AND uc.docstatus = 1 AND uc.bill_run_type = %s AND uc.unit = %s AND uc.bill_period = %s;""", (self.bill_run_type, i.unit, self.bill_period), as_dict=1) for s in sitem: m_doc = doc.append( 'items', { "item_code": s.item, "item_name": s.description, "description": s.description, "qty": s.qty, "rate": s.rate, "amount": s.rate * s.qty }) doc.flags.ignore_mandatory = True doc.insert() "Add Invoice Detail on Bill Run" self.append( 'bill_run_invoices', { "invoice": doc.name, "date": doc.posting_date, "customer": doc.customer_name, "amount": doc.total })
def getDueDate(date, customer): return get_due_date( date, 'Customer', str(customer), frappe.db.get_single_value('Global Defaults', 'default_company'), date)