Skip to content

Commit

Permalink
feat: Default sales tax account in shopify
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Oct 24, 2023
1 parent 9851d84 commit 7c18889
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
"cash_bank_account",
"column_break_19",
"cost_center",
"inventory_settings_section",
"column_break_22",
"section_break_25",
"sales_order_series",
"delivery_note_series",
Expand All @@ -38,6 +36,10 @@
"section_break_22",
"html_16",
"taxes",
"section_break_zeoy",
"default_sales_tax_account",
"column_break_qibo",
"default_shipping_charges_account",
"erpnext_to_shopify_sync_section",
"upload_erpnext_items",
"update_shopify_item_on_update",
Expand Down Expand Up @@ -124,11 +126,6 @@
"mandatory_depends_on": "eval:doc.enable_shopify",
"options": "Customer Group"
},
{
"fieldname": "inventory_settings_section",
"fieldtype": "Section Break",
"label": "Inventory Settings"
},
{
"description": "If individual warehouse are not mapped, the default warehouse is considered for transactions.",
"fieldname": "warehouse",
Expand Down Expand Up @@ -235,10 +232,6 @@
"mandatory_depends_on": "eval:doc.enable_shopify",
"options": "Shopify Tax Account"
},
{
"fieldname": "column_break_22",
"fieldtype": "Column Break"
},
{
"fieldname": "erpnext_to_shopify_sync_section",
"fieldtype": "Section Break",
Expand Down Expand Up @@ -371,12 +364,35 @@
"fieldname": "consolidate_taxes",
"fieldtype": "Check",
"label": "Consolidate Taxes in Order"
},
{
"description": "When no sales tax mapping is found this tax account will be used as the default account. This is only applied for Sales Tax. Any shipping related charges still need to be mapped separately.",
"fieldname": "default_sales_tax_account",
"fieldtype": "Link",
"label": "Default Sales Tax Account",
"options": "Account"
},
{
"fieldname": "section_break_zeoy",
"fieldtype": "Section Break",
"hide_border": 1
},
{
"fieldname": "column_break_qibo",
"fieldtype": "Column Break"
},
{
"description": "When no shipping charge account mapping is found this account will be used as the default account.",
"fieldname": "default_shipping_charges_account",
"fieldtype": "Link",
"label": "Default Shipping Charges Account",
"options": "Account"
}
],
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2023-02-10 10:36:12.940019",
"modified": "2023-10-24 10:38:49.247431",
"modified_by": "Administrator",
"module": "shopify",
"name": "Shopify Setting",
Expand Down
17 changes: 13 additions & 4 deletions ecommerce_integrations/shopify/order.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from typing import Literal, Optional

import frappe
from frappe import _
Expand All @@ -22,6 +23,11 @@
from ecommerce_integrations.utils.price_list import get_dummy_price_list
from ecommerce_integrations.utils.taxation import get_dummy_tax_category

DEFAULT_TAX_FIELDS = {
"sales_tax": "default_sales_tax_account",
"shipping": "default_shipping_charges_account",
}


def sync_sales_order(payload, request_id=None):
order = payload
Expand Down Expand Up @@ -197,7 +203,7 @@ def get_order_taxes(shopify_order, setting, items):
taxes.append(
{
"charge_type": "Actual",
"account_head": get_tax_account_head(tax),
"account_head": get_tax_account_head(tax, charge_type="sales_tax"),
"description": (
get_tax_account_description(tax) or f"{tax.get('title')} - {tax.get('rate') * 100.0:.2f}%"
),
Expand Down Expand Up @@ -252,13 +258,16 @@ def consolidate_order_taxes(taxes):
return tax_account_wise_data.values()


def get_tax_account_head(tax):
def get_tax_account_head(tax, charge_type: Optional[Literal["shipping", "sales_tax"]] = None):
tax_title = str(tax.get("title"))

tax_account = frappe.db.get_value(
"Shopify Tax Account", {"parent": SETTING_DOCTYPE, "shopify_tax": tax_title}, "tax_account",
)

if not tax_account and charge_type:
tax_account = frappe.db.get_single_value(SETTING_DOCTYPE, DEFAULT_TAX_FIELDS[charge_type])

if not tax_account:
frappe.throw(_("Tax Account not specified for Shopify Tax {0}").format(tax.get("title")))

Expand Down Expand Up @@ -306,7 +315,7 @@ def update_taxes_with_shipping_lines(taxes, shipping_lines, setting, items, taxe
taxes.append(
{
"charge_type": "Actual",
"account_head": get_tax_account_head(shipping_charge),
"account_head": get_tax_account_head(shipping_charge, charge_type="shipping"),
"description": get_tax_account_description(shipping_charge) or shipping_charge["title"],
"tax_amount": shipping_charge_amount,
"cost_center": setting.cost_center,
Expand All @@ -317,7 +326,7 @@ def update_taxes_with_shipping_lines(taxes, shipping_lines, setting, items, taxe
taxes.append(
{
"charge_type": "Actual",
"account_head": get_tax_account_head(tax),
"account_head": get_tax_account_head(tax, charge_type="sales_tax"),
"description": (
get_tax_account_description(tax) or f"{tax.get('title')} - {tax.get('rate') * 100.0:.2f}%"
),
Expand Down

0 comments on commit 7c18889

Please sign in to comment.