def calculate_excise_tax(doc, compliance_items): total_excise_tax = total_shipping_charge = 0 if doc.get("taxes"): for tax in doc.get("taxes"): if tax.get("account_head") == get_company_default( doc.get("company"), "default_shipping_account"): total_shipping_charge += tax.tax_amount # if order type is sample then pass tax_ammount zero to remove excise tax row automatically. if not doc.get("order_type") == "Sample": for item in (doc.get("items") or []): compliance_item = next( (data for data in compliance_items if data.get("item_code") == item.get("item_code")), None) if not compliance_item: continue # fetch either the transaction rate or price list rate, whichever is higher price_list_rate = item.get("price_list_rate") or 0 rate = item.get("rate") or 0 qty = item.get("qty") or 0 max_item_rate = max([price_list_rate, rate]) if max_item_rate == 0: continue if not doc.net_total: return # calculate the total excise tax for each item item_shipping_charge = (total_shipping_charge / doc.net_total) * (max_item_rate * qty) item_cost_with_shipping = (max_item_rate * qty) + item_shipping_charge item_cost_after_markup = item_cost_with_shipping + ( item_cost_with_shipping * MARKUP_PERCENTAGE / 100) total_excise_tax += item_cost_after_markup * EXCISE_TAX_RATE / 100 excise_tax_row = { 'category': 'Total', 'add_deduct_tax': 'Add', 'charge_type': 'Actual', 'description': 'Excise Tax', 'account_head': get_company_default(doc.get("company"), "default_excise_tax_account"), 'tax_amount': total_excise_tax } return excise_tax_row
def get_double_matched_entry(self, amount, against): from erpnext.accounts.utils import get_company_default base_gl_entry = { "posting_date": self.posting_date, "voucher_type": self.doctype, "voucher_no": self.name, "cost_center": get_company_default(self.company, "cost_center"), "company": self.company } # use frappe._dict to make a copy of the dict and don't modify the original debit_gl_entry = frappe._dict(base_gl_entry).update({ "party_type": self.party_type, "party": self.party, "account": self.party_account, "account_currency": frappe.get_value("Account", self.party_account, "account_currency"), "against": against, "debit": flt(amount) * flt(self.exchange_rate), "debit_in_account_currency": flt(amount), }) # use frappe._dict to make a copy of the dict and don't modify the original credit_gl_entry = frappe._dict(base_gl_entry).update({ "account": against, "account_currency": frappe.get_value("Account", against, "account_currency"), "against": self.party, "credit": flt(amount) * flt(self.exchange_rate), "credit_in_account_currency": flt(amount), }) return [debit_gl_entry, credit_gl_entry]
def get_double_matched_entry(self, row): from erpnext.accounts.utils import get_company_default base_gl_entry = { "posting_date": self.posting_date, "voucher_type": self.doctype, "voucher_no": self.name, "cost_center": get_company_default(self.company, "cost_center"), "company": self.company } # use frappe._dict to make a copy of the dict and don't modify the original debit_gl_entry = frappe._dict(base_gl_entry).update({ "account": row.against_account, "account_currency": row.against_account_currency, "against": self.party, "debit": row.base_allocated_amount, "debit_in_account_currency": row.allocated_amount, }) # use frappe._dict to make a copy of the dict and don't modify the original credit_gl_entry = frappe._dict(base_gl_entry).update({ "party_type": self.party_type, "party": self.party, "account": row.account, "account_currency": row.account_currency, "against": row.against_account, "credit": row.base_allocated_amount, "credit_in_account_currency": row.allocated_amount, }) return [debit_gl_entry, credit_gl_entry]
def get_difference_account(purpose, company): if purpose == 'Stock Reconciliation': account = get_company_default(company, "stock_adjustment_account") else: account = frappe.db.get_value('Account', {'is_group': 0, 'company': company, 'account_type': 'Temporary'}, 'name') return account
def calculate_item_cultivation_tax(doc, item, cultivation_taxes=None): compliance_items = frappe.get_all('Compliance Item', fields=['item_code', 'enable_cultivation_tax', 'item_category']) compliance_item = next((data for data in compliance_items if data.get("item_code") == item.get("item_code")), None) if not compliance_item or not compliance_item.enable_cultivation_tax: return cultivation_taxes flower_tax_account = get_company_default(doc.get("company"), "default_cultivation_tax_account_flower") leaf_tax_account = get_company_default(doc.get("company"), "default_cultivation_tax_account_leaf") plant_tax_account = get_company_default(doc.get("company"), "default_cultivation_tax_account_plant") if not cultivation_taxes: cultivation_taxes = dict.fromkeys([flower_tax_account, leaf_tax_account, plant_tax_account], float()) qty_in_ounces = convert_to_ounces(item.get("uom"), item.get("qty")) if compliance_item.item_category == "Dry Flower": cultivation_tax = qty_in_ounces * DRY_FLOWER_TAX_RATE cultivation_taxes[flower_tax_account] += cultivation_tax elif compliance_item.item_category == "Dry Leaf": cultivation_tax = qty_in_ounces * DRY_LEAF_TAX_RATE cultivation_taxes[leaf_tax_account] += cultivation_tax elif compliance_item.item_category == "Fresh Plant": cultivation_tax = qty_in_ounces * FRESH_PLANT_TAX_RATE cultivation_taxes[plant_tax_account] += cultivation_tax elif compliance_item.item_category == "Based on Raw Materials": # calculate cultivation tax based on weight of raw materials if not item.get("cultivation_weight_uom"): frappe.throw(_("Row #{0}: Please set a cultivation weight UOM".format(item.get("idx")))) if item.get("flower_weight"): flower_weight_in_ounce = convert_to_ounces(item.get("cultivation_weight_uom"), item.get("flower_weight")) flower_cultivation_tax = (flower_weight_in_ounce * DRY_FLOWER_TAX_RATE) cultivation_taxes[flower_tax_account] += flower_cultivation_tax if item.get("leaf_weight"): leaf_weight_in_ounce = convert_to_ounces(item.get("cultivation_weight_uom"), item.get("leaf_weight")) leaf_cultivation_tax = (leaf_weight_in_ounce * DRY_LEAF_TAX_RATE) cultivation_taxes[leaf_tax_account] += leaf_cultivation_tax if item.get("plant_weight"): plant_weight_in_ounce = convert_to_ounces(item.get("cultivation_weight_uom"), item.get("plant_weight")) plant_cultivation_tax = (plant_weight_in_ounce * FRESH_PLANT_TAX_RATE) cultivation_taxes[plant_tax_account] += plant_cultivation_tax return cultivation_taxes
def get_difference_account(purpose, company): if purpose == "Stock Reconciliation": account = get_company_default(company, "stock_adjustment_account") else: account = frappe.db.get_value("Account", { "is_group": 0, "company": company, "account_type": "Temporary" }, "name") return
def make_gl_entries(self, cancel=False, adv_adj=False): from erpnext.accounts.general_ledger import make_gl_entries from erpnext.accounts.utils import get_company_default loan_doc = frappe.get_doc( self.meta.get_field("loan").options, self.loan) income_account = get_company_default(loan_doc.company, "default_income_account") gl_map = loan_doc.get_double_matched_entry(self.total_amount, income_account) make_gl_entries(gl_map, cancel=cancel, adv_adj=adv_adj, merge_entries=False)
def autoname(item, method=None): """ Item Code = a + b + c + d + e, where a = abbreviated Company; all caps. b = abbreviated Brand; all caps. c = abbreviated Item Group; all caps. d = abbreviated Item Name; all caps. e = variant ID number; has to be incremented. """ if not frappe.db.get_single_value("Stock Settings", "autoname_item"): return # Get abbreviations item_group_abbr = get_abbr(item.item_group) item_name_abbr = get_abbr(item.item_name, 3) default_company = get_default_company() if default_company: company_abbr = get_company_default(default_company, "abbr") brand_abbr = get_abbr(item.brand, max_length=len(company_abbr)) brand_abbr = brand_abbr if company_abbr != brand_abbr else None params = list( filter( None, [company_abbr, brand_abbr, item_group_abbr, item_name_abbr])) item_code = "-".join(params) else: brand_abbr = get_abbr(item.brand) params = list( filter(None, [brand_abbr, item_group_abbr, item_name_abbr])) item_code = "-".join(params) # Get count count = len( frappe.get_all("Item", filters={"name": ["like", "%{}%".format(item_code)]})) if count > 0: item_code = "-".join([item_code, cstr(count + 1)]) # Set item document name item.name = item.item_code = item_code if not method: return item.item_code
def get_company_default(self, fieldname): from erpnext.accounts.utils import get_company_default return get_company_default(self.company, fieldname)
def execute(filters=None): period_list = get_period_list(filters.from_date, filters.to_date, filters.periodicity, filters.accumulated_values, filters.company) ignore_accumulated_values_for_fy = True if filters.periodicity == "Custom": ignore_accumulated_values_for_fy = False #fetch data for the income and expense accounts income = get_data( filters.company, "Income", "Credit", period_list, filters=filters, accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy=ignore_accumulated_values_for_fy) expense = get_data( filters.company, "Expense", "Debit", period_list, filters=filters, accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy=ignore_accumulated_values_for_fy) #add the section for income data = [] data.extend(income or []) #get direct and indirect expense account names gross_profit_loss = None direct_expense_account = frappe.get_value("Company", get_default_company(), "default_direct_expenses") indirect_expense_account = frappe.get_value("Company", get_default_company(), "default_indirect_expenses") company_abbr = get_company_default(get_default_company(), "abbr") direct_expenses = None for expense_item in expense: data.append(expense_item) #add gross profit line item on the PL statement if expense_item.get("group_account_summary", False) and expense_item.get( "_account") == direct_expense_account: direct_expenses = expense_item gross_profit_loss = get_profit_loss(income, expense_item, period_list, filters.company, "Gross Profit", indent=1, is_group=0) if gross_profit_loss: data.append(gross_profit_loss) gross_profit_loss = None #add the line for net operating income / loss if expense_item.get("group_account_summary", False) and expense_item.get( "_account") == indirect_expense_account: operating_profit_loss = get_profit_loss( income, expense_item, period_list, filters.company, "Net Operating Profit", indent=expense_item.get("indent"), is_group=0, direct_expenses=direct_expenses) if operating_profit_loss: data.append(operating_profit_loss) operating_profit_loss = None #add the line for net profit / loss net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company, filters.presentation_currency) if net_profit_loss: data.append(net_profit_loss) columns = get_columns(filters.periodicity, period_list, filters.accumulated_values, filters.company) chart = get_chart_data(filters, columns, income, expense, net_profit_loss) return columns, data, None, chart