feat: input website, email, phone_no if not already set in company

This commit is contained in:
khushi8112
2025-10-01 12:47:42 +05:30
parent abc7bf2fd6
commit 98838b1dd5
2 changed files with 65 additions and 29 deletions

View File

@@ -282,18 +282,30 @@ class SalesInvoice(SellingController):
def before_print(self, settings=None):
from frappe.contacts.doctype.address.address import get_address_display_list
company_logo = frappe.get_value("Company", self.company, ["company_logo"])
company_details = frappe.get_value(
"Company", self.company, ["company_logo", "website", "phone_no", "email"], as_dict=True
)
address_display_list = get_address_display_list("Company", self.company)
address_line = address_display_list[0] if address_display_list else ""
address_line = ""
if address_display_list and len(address_display_list) > 0:
address_line = address_display_list[0]["address_line1"]
required_fields = [
company_details.get("company_logo"),
company_details.get("website"),
company_details.get("phone_no"),
company_details.get("email"),
self.company_address,
address_line,
]
if not address_line or not company_logo or not self.company_address:
if not all(required_fields):
frappe.publish_realtime(
"sales_invoice_before_print",
{
"company_logo": company_logo,
"company_logo": company_details.get("company_logo"),
"website": company_details.get("website"),
"phone_no": company_details.get("phone_no"),
"email": company_details.get("email"),
"address_line": address_line,
"company": self.company,
"company_address_display": self.company_address,
@@ -2830,18 +2842,15 @@ def save_company_master_details(name, company, details):
if isinstance(details, str):
details = frappe.parse_json(details)
if details.get("company_logo"):
frappe.db.set_value(
"Company",
company,
{
"company_logo": details.get("company_logo"),
},
)
company_fields = ["company_logo", "website", "phone_no", "email"]
updated_fields = {field: details.get(field) for field in company_fields if details.get(field)}
company_address = None
if updated_fields:
frappe.db.set_value("Company", company, updated_fields)
company_address = details.get("company_address")
if details.get("address_line1"):
address = frappe.get_doc(
address_doc = frappe.get_doc(
{
"doctype": "Address",
"address_title": details.get("address_title"),
@@ -2854,11 +2863,9 @@ def save_company_master_details(name, company, details):
"is_your_company_address": 1,
"links": [{"link_doctype": "Company", "link_name": company}],
}
).insert(ignore_permissions=True)
company_address = address.name
else:
company_address = details.get("company_address")
)
address_doc.insert(ignore_permissions=True)
company_address = address_doc.name
if company_address:
current_display = frappe.db.get_value("Sales Invoice", name, "company_address_display")

View File

@@ -16,15 +16,33 @@ frappe.realtime.on("sales_invoice_before_print", (data) => {
hidden: data.company_logo ? 1 : 0,
},
{
label: "Address Title",
fieldname: "address_title",
label: "Website",
fieldname: "website",
fieldtype: "Data",
reqd: data.address_line ? 0 : 1,
hidden: data.address_line ? 1 : 0,
reqd: data.website ? 0 : 1,
hidden: data.website ? 1 : 0,
},
{
label: "Address Line 1",
fieldname: "address_line1",
label: "Phone No",
fieldname: "phone_no",
fieldtype: "Data",
reqd: data.phone_no ? 0 : 1,
hidden: data.phone_no ? 1 : 0,
},
{
label: "Email",
fieldname: "email",
fieldtype: "Data",
reqd: data.email ? 0 : 1,
hidden: data.email ? 1 : 0,
},
{
fieldname: "section_break_1",
fieldtype: "Section Break",
},
{
label: "Address Title",
fieldname: "address_title",
fieldtype: "Data",
reqd: data.address_line ? 0 : 1,
hidden: data.address_line ? 1 : 0,
@@ -38,6 +56,17 @@ frappe.realtime.on("sales_invoice_before_print", (data) => {
reqd: data.address_line ? 0 : 1,
hidden: data.address_line ? 1 : 0,
},
{
label: "Address Line",
fieldname: "address_line1",
fieldtype: "Data",
reqd: data.address_line ? 0 : 1,
hidden: data.address_line ? 1 : 0,
},
{
fieldname: "column_break_1",
fieldtype: "Column Break",
},
{
label: "City",
fieldname: "city",
@@ -78,8 +107,8 @@ frappe.realtime.on("sales_invoice_before_print", (data) => {
},
};
},
reqd: data.address_line ? 1 : 0,
hidden: data.address_line ? 0 : 1,
reqd: data.address_line && !data.company_address ? 1 : 0,
hidden: data.address_line && !data.company_address ? 0 : 1,
},
],
primary_action_label: "Save",