mirror of
https://github.com/itsdave-de/msp.git
synced 2025-05-06 15:35:12 +02:00
Merge branch 'main' of https://github.com/itsdave-de/msp
This commit is contained in:
commit
65386bae8e
@ -12,6 +12,9 @@
|
|||||||
"invoices_from_delivery_notes_section",
|
"invoices_from_delivery_notes_section",
|
||||||
"customer",
|
"customer",
|
||||||
"get_invoice",
|
"get_invoice",
|
||||||
|
"it_contract_invoices_section",
|
||||||
|
"billing_month",
|
||||||
|
"contract_invoices",
|
||||||
"statistics",
|
"statistics",
|
||||||
"date",
|
"date",
|
||||||
"invoice_count",
|
"invoice_count",
|
||||||
@ -74,12 +77,28 @@
|
|||||||
"fieldname": "log",
|
"fieldname": "log",
|
||||||
"fieldtype": "Small Text",
|
"fieldtype": "Small Text",
|
||||||
"label": "Log"
|
"label": "Log"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "billing_month",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Billing Month"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "contract_invoices",
|
||||||
|
"fieldtype": "Button",
|
||||||
|
"label": "Contract Invoices",
|
||||||
|
"options": "get_invoices"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "it_contract_invoices_section",
|
||||||
|
"fieldtype": "Section Break",
|
||||||
|
"label": "IT Contract Invoices"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"migration_hash": "81a435d8fdde574c14c22be58f9e32ca",
|
"migration_hash": "d64bd35ec0b0d442bcfc080be217f2f6",
|
||||||
"modified": "2022-09-22 14:23:33.413375",
|
"modified": "2023-05-31 11:12:52.773165",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "MSP",
|
"module": "MSP",
|
||||||
"name": "Auto Invoice Generator",
|
"name": "Auto Invoice Generator",
|
||||||
|
@ -127,11 +127,12 @@ class AutoInvoiceGenerator(Document):
|
|||||||
print(len(customer_list))
|
print(len(customer_list))
|
||||||
cust_count = 0
|
cust_count = 0
|
||||||
invoice_count = 0
|
invoice_count = 0
|
||||||
|
log_list = []
|
||||||
for cust in customer_list:
|
for cust in customer_list:
|
||||||
cust_doc = frappe.get_doc("Customer",cust)
|
cust_doc = frappe.get_doc("Customer",cust)
|
||||||
invoice_in_draft = frappe.get_all("Sales Invoice", filters = {"status" : "Draft", "customer": cust})
|
invoice_in_draft = frappe.get_all("Sales Invoice", filters = {"status" : "Draft", "customer": cust})
|
||||||
if len(invoice_in_draft) > 0:
|
if len(invoice_in_draft) > 0:
|
||||||
self.log = "Für Kunde"+ " "+ cust + " wurden keine Rechnungen erstellt, da noch nicht berechnete Rechnungen in Draft vorhanden"
|
log_list.append("Für Kunde"+ " "+ cust + " wurden keine Rechnungen erstellt, da noch nicht berechnete Rechnungen in Draft vorhanden")
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
cust_count += 1
|
cust_count += 1
|
||||||
@ -238,6 +239,12 @@ class AutoInvoiceGenerator(Document):
|
|||||||
self.date = datetime.today().strftime('%Y-%m-%d')
|
self.date = datetime.today().strftime('%Y-%m-%d')
|
||||||
self.invoice_count = invoice_count
|
self.invoice_count = invoice_count
|
||||||
self.customer_count = cust_count
|
self.customer_count = cust_count
|
||||||
|
log_str = ""
|
||||||
|
for i in log_list:
|
||||||
|
log_str += i + "\n"
|
||||||
|
|
||||||
|
self.log = log_str
|
||||||
|
self.save()
|
||||||
|
|
||||||
|
|
||||||
def create_invoice_doc_item(self, item):
|
def create_invoice_doc_item(self, item):
|
||||||
@ -292,4 +299,108 @@ class AutoInvoiceGenerator(Document):
|
|||||||
invoice_doc.append("taxes", new_tax)
|
invoice_doc.append("taxes", new_tax)
|
||||||
invoice_doc.save()
|
invoice_doc.save()
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def get_invoices(self):
|
||||||
|
contract_list = frappe.get_all("IT Contract", filters ={"status":"active", "billing_active":1})
|
||||||
|
print(contract_list)
|
||||||
|
if len(contract_list)>0:
|
||||||
|
count = 0
|
||||||
|
for contr in contract_list:
|
||||||
|
contract= frappe.get_doc("IT Contract",contr.name)
|
||||||
|
#if contract.billing_active == 1:
|
||||||
|
if contract.invoicing_in_advance == 1:
|
||||||
|
billing_month = self.set_billing_month_plus(self.billing_month)
|
||||||
|
print(billing_month)
|
||||||
|
else:
|
||||||
|
billing_month = self.billing_month
|
||||||
|
customer = contract.customer
|
||||||
|
items = contract.items
|
||||||
|
if contract.introduction_text:
|
||||||
|
introduction = str(contract.introduction_text) +"Leistungszeitraum " + billing_month
|
||||||
|
else:
|
||||||
|
introduction = "Leistungszeitraum " + billing_month
|
||||||
|
title = contract.it_contract_type+ " " + billing_month + " " + contract.customer_name
|
||||||
|
print(title)
|
||||||
|
inv_title_list = frappe.get_all("Sales Invoice", filters = {"title":title})
|
||||||
|
if len(inv_title_list) == 0:
|
||||||
|
count += 1
|
||||||
|
invoice_items = [self.create_contract_invoice_doc_item(el) for el in items]
|
||||||
|
invoice_doc = self.create_contract_invoice(customer,invoice_items,title, introduction)
|
||||||
|
if count == 0:
|
||||||
|
frappe.msgprint("Für den angegebenen Zeitraum wurden bereits alle Rechnungen erstellt")
|
||||||
|
|
||||||
|
|
||||||
|
else:
|
||||||
|
frappe.msgprint("Keine Kontrakte abzurechnen")
|
||||||
|
|
||||||
|
def create_contract_invoice_doc_item(self, item):
|
||||||
|
#Funktion kreiert Invoice Item aus den gegebenen IT Contract Items
|
||||||
|
invoice_doc_item = frappe.get_doc({
|
||||||
|
"doctype": "Sales Invoice Item",
|
||||||
|
"item_code": item.item_code,
|
||||||
|
"description": item.description,
|
||||||
|
"qty": item.qty,
|
||||||
|
"uom" : "Stk",
|
||||||
|
"rate": item.rate,
|
||||||
|
|
||||||
|
})
|
||||||
|
return invoice_doc_item
|
||||||
|
|
||||||
|
def create_contract_invoice(self,cust,invoice_doc_items,title, introduction):
|
||||||
|
invoice_doc = frappe.get_doc({
|
||||||
|
"doctype": "Sales Invoice",
|
||||||
|
"title": title,
|
||||||
|
"customer": cust,
|
||||||
|
"company": frappe.get_doc("Global Defaults").default_company,
|
||||||
|
"items": invoice_doc_items,
|
||||||
|
"introduction_text":introduction,
|
||||||
|
|
||||||
|
})
|
||||||
|
if len(invoice_doc_items)>0:
|
||||||
|
|
||||||
|
settings_doc = frappe.get_single("Auto Invoice Generator Settings")
|
||||||
|
customer_doc = frappe.get_doc("Customer", cust )
|
||||||
|
|
||||||
|
if customer_doc.payment_terms:
|
||||||
|
invoice_doc.payment_terms_template = customer_doc.payment_terms
|
||||||
|
else:
|
||||||
|
invoice_doc.payment_terms_template = settings_doc.payment_terms_template
|
||||||
|
invoice_doc.tc_name = settings_doc.tc_name
|
||||||
|
tac_doc = frappe.get_doc("Terms and Conditions", settings_doc.tc_name)
|
||||||
|
invoice_doc.terms = tac_doc.terms
|
||||||
|
|
||||||
|
invoice_doc.taxes_and_charges = party_st(invoice_doc.customer, "Customer", invoice_doc.posting_date, invoice_doc.company)
|
||||||
|
taxes = frappe.get_doc("Sales Taxes and Charges Template", settings_doc.taxes_and_charges).taxes
|
||||||
|
|
||||||
|
for tax in taxes:
|
||||||
|
new_tax = frappe.get_doc({
|
||||||
|
"doctype": "Sales Taxes and Charges",
|
||||||
|
"charge_type": tax.charge_type,
|
||||||
|
"account_head": tax.account_head,
|
||||||
|
"rate": tax.rate,
|
||||||
|
"description": tax.description
|
||||||
|
})
|
||||||
|
invoice_doc.append("taxes", new_tax)
|
||||||
|
invoice_doc.save()
|
||||||
|
|
||||||
|
def set_billing_month_plus(self,date):
|
||||||
|
|
||||||
|
month, year = date.split('.')
|
||||||
|
month = int(month)
|
||||||
|
year = int(year)
|
||||||
|
|
||||||
|
# Den Monat um eins erhöhen
|
||||||
|
month += 1
|
||||||
|
|
||||||
|
# Wenn der Monat größer als 12 ist, das Jahr um eins erhöhen und den Monat auf 1 setzen
|
||||||
|
if month > 12:
|
||||||
|
month = 1
|
||||||
|
year += 1
|
||||||
|
|
||||||
|
|
||||||
|
new_billing_month = "{:02d}.{}".format(month, year)
|
||||||
|
return new_billing_month
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
"column_break_19",
|
"column_break_19",
|
||||||
"accounting_period",
|
"accounting_period",
|
||||||
"billing_active",
|
"billing_active",
|
||||||
|
"invoicing_in_advance",
|
||||||
"history_section",
|
"history_section",
|
||||||
"delivery_note_list"
|
"delivery_note_list"
|
||||||
],
|
],
|
||||||
@ -178,10 +179,17 @@
|
|||||||
"fieldname": "introduction_text",
|
"fieldname": "introduction_text",
|
||||||
"fieldtype": "Text Editor",
|
"fieldtype": "Text Editor",
|
||||||
"label": "Introduction Text"
|
"label": "Introduction Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fieldname": "invoicing_in_advance",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Invoicing in advance"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-02-22 20:09:42.111402",
|
"migration_hash": "c5e40dc088dd7fd9d7d8cc905833c3f8",
|
||||||
|
"modified": "2023-05-31 11:06:24.441274",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "MSP",
|
"module": "MSP",
|
||||||
"name": "IT Contract",
|
"name": "IT Contract",
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fetch_from": "item_code.description",
|
"fetch_from": "item_code.description",
|
||||||
|
"fetch_if_empty": 1,
|
||||||
"fieldname": "description",
|
"fieldname": "description",
|
||||||
"fieldtype": "Text Editor",
|
"fieldtype": "Text Editor",
|
||||||
"label": "Description"
|
"label": "Description"
|
||||||
@ -56,7 +57,8 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-02-22 19:51:22.759330",
|
"migration_hash": "9e4c62717954cad74301d644a4b105a2",
|
||||||
|
"modified": "2023-05-31 11:45:32.701190",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "MSP",
|
"module": "MSP",
|
||||||
"name": "IT Contract Item",
|
"name": "IT Contract Item",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user