def calculate_cannabis_tax(doc): compliance_items = frappe.get_all('Compliance Item', fields=['item_code', 'enable_cultivation_tax', 'item_category']) if not compliance_items: return if doc.doctype in ("Purchase Order", "Purchase Invoice", "Purchase Receipt"): # calculate cultivation tax for buying cycle cultivation_taxes = calculate_cultivation_tax(doc) for account, tax in cultivation_taxes.items(): cultivation_tax_row = get_cultivation_tax_row(account, tax) set_taxes(doc, cultivation_tax_row) elif doc.doctype in ("Quotation", "Sales Order", "Sales Invoice", "Delivery Note"): # customer license is required to inspect license type if doc.doctype == "Quotation": if doc.quotation_to != "Customer": return default_customer_license = get_default_license("Customer", doc.party_name) elif doc.doctype in ("Sales Order", "Sales Invoice", "Delivery Note"): default_customer_license = get_default_license("Customer", doc.customer) if not default_customer_license: frappe.msgprint(_("Please set a default license for {0} to calculate taxes").format(doc.customer)) return license_for = frappe.db.get_value("Compliance Info", default_customer_license, "license_for") if license_for == "Distributor": # calculate cultivation tax for selling cycle if customer is a distributor cultivation_taxes = calculate_cultivation_tax(doc) for account, tax in cultivation_taxes.items(): cultivation_tax_row = get_cultivation_tax_row(account, tax) set_taxes(doc, cultivation_tax_row) elif license_for == "Retailer": # calculate excise tax for selling cycle is customer is a retailer or end-consumer excise_tax_row = calculate_excise_tax(doc, compliance_items) set_taxes(doc, excise_tax_row)
def get_entity_license(doc, party_type, party_name): # get the default license for the given party license_record = get_default_license(party_type, party_name) if not license_record: return # show a warning if a license exists and is expired, and only if compliance items are present is_compliance = validate_doc_compliance(doc) if is_compliance: license_expiry_date, license_number = frappe.db.get_value( "Compliance Info", license_record, ["license_expiry_date", "license_number"]) if not license_expiry_date: frappe.msgprint(_("We could not verify the status of license number {0}. Proceed with caution.").format( frappe.bold(license_number))) elif getdate(license_expiry_date) < getdate(nowdate()): frappe.msgprint(_("Our records indicate that the license number {0} has expired on {1}. Proceed with caution.").format( frappe.bold(license_number), frappe.bold(formatdate(license_expiry_date)))) return license_record
def get_party_addresses_and_contact(party_type, party, party_group): data = [] # Build party details party_details = frappe._dict() if not party_type: return [] filters = {"name": party} if party else None party_list = frappe.get_list(party_type, filters=filters, fields=["name", party_group]) party_names = [d.get("name") for d in party_list] party_groups = {d.get("name"): d.get(party_group) for d in party_list} for d in party_names: party_details.setdefault(d, frappe._dict()) party_details = get_party_details(party_type, party_names, party_details) # Add a row for each party address and contact, along with party details for party, details in iteritems(party_details): territory = sales_partner = license_type = license_number = None if party_type == "Customer": territory = frappe.db.get_value(party_type, party, "territory") sales_partner = frappe.db.get_value(party_type, party, "default_sales_partner") if party_type in ("Customer", "Supplier"): license_record = get_default_license(party_type, party) if frappe.db.exists("Compliance Info", license_record): license_type, license_number = frappe.db.get_value( "Compliance Info", license_record, ["license_type", "license_number"]) # If no addresses and contacts exist, add a single row to display the party addresses = details.get("address", []) contacts = details.get("contact", []) max_length = max(len(addresses), len(contacts), 1) for idx in range(max_length): result = [party] result.append(party_groups.get(party)) if party_type == "Customer": result.extend([territory, sales_partner]) if party_type in ("Customer", "Supplier"): result.extend([license_type, license_number]) address = addresses[idx] if idx < len( addresses) else add_blank_columns_for("Address") contact = contacts[idx] if idx < len( contacts) else add_blank_columns_for("Contact") result.extend(address) result.extend(contact) data.append(result) return data
def execute(): sync_customizations("bloomstack_core") compliance_info = frappe.get_all('Compliance Info', fields=['name']) if not compliance_info: return sales_orders = frappe.get_all("Sales Order", fields=["customer", "name"]) sales_invoices = frappe.get_all("Sales Invoice", fields=["customer", "name"]) delivery_notes = frappe.get_all("Sales Invoice", fields=["customer", "name"]) quotations = frappe.get_all("Quotation", fields=["party_name", "name", "quotation_to"]) supplier_quotations = frappe.get_all("Supplier Quotation", fields=["supplier", "name"]) purchase_orders = frappe.get_all("Purchase Order", fields=["supplier", "name"]) purchase_invoices = frappe.get_all("Purchase Invoice", fields=["supplier", "name"]) purchase_receipts = frappe.get_all("Purchase Receipt", fields=["supplier", "name"]) for doc in sales_orders: license = get_default_license("Customer", doc.customer) if not license: continue frappe.db.set_value("Sales Order", doc.name, "license", license) for doc in sales_invoices: license = get_default_license("Customer", doc.customer) if not license: continue frappe.db.set_value("Sales Invoice", doc.name, "license", license) for doc in delivery_notes: license = get_default_license("Customer", doc.customer) if not license: continue frappe.db.set_value("Delivery Note", doc.name, "license", license) for doc in quotations: if doc.quotation_to == "Customer": license = get_default_license("Customer", doc.party_name) if not license: continue frappe.db.set_value("Quotation", doc.name, "license", license) for doc in supplier_quotations: license = get_default_license("Supplier", doc.supplier) if not license: continue frappe.db.set_value("Supplier Quotation", doc.name, "license", license) for doc in purchase_orders: license = get_default_license("Supplier", doc.supplier) if not license: continue frappe.db.set_value("Purchase Order", doc.name, "license", license) for doc in purchase_invoices: license = get_default_license("Supplier", doc.supplier) if not license: continue frappe.db.set_value("Purchase Invoice", doc.name, "license", license) for doc in purchase_receipts: license = get_default_license("Supplier", doc.supplier) if not license: continue frappe.db.set_value("Purchase Receipt", doc.name, "license", license)