Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions woocommerceconnector/sync_orders.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import unicode_literals
from types import NoneType
import frappe
from frappe import _
from .exceptions import woocommerceError
Expand All @@ -10,7 +11,6 @@
import requests.exceptions
import base64, requests, datetime, os


def sync_orders():
sync_woocommerce_orders()

Expand Down Expand Up @@ -357,7 +357,7 @@ def get_order_taxes(woocommerce_order, woocommerce_settings):

taxes.append({
"charge_type": "Actual",
"account_head": get_tax_account_head(woocommerce_tax),
"account_head": get_tax_account_head(woocommerce_tax, woocommerce_settings.default_tax_account),
"description": "{0} - {1}%".format(name, rate),
"rate": rate,
"tax_amount": flt(tax.get("tax_total") or 0) + flt(tax.get("shipping_tax_total") or 0),
Expand Down Expand Up @@ -396,7 +396,7 @@ def update_taxes_with_shipping_lines(taxes, shipping_lines, woocommerce_settings
#
taxes.append({
"charge_type": "Actual",
"account_head": get_shipping_account_head(shipping_charge),
"account_head": get_shipping_account_head(shipping_charge, woocommerce_settings.default_shipping_account),
"description": shipping_charge["method_title"],
"tax_amount": shipping_charge["total"],
"cost_center": woocommerce_settings.cost_center
Expand All @@ -406,26 +406,32 @@ def update_taxes_with_shipping_lines(taxes, shipping_lines, woocommerce_settings



def get_shipping_account_head(shipping):
shipping_title = shipping.get("method_title").encode("utf-8")

def get_shipping_account_head(shipping, default):
shipping_title = shipping.get("method_title")
if shipping_title:
shipping_account = frappe.db.get_value("woocommerce Tax Account", \
{"parent": "WooCommerce Config", "woocommerce_tax": shipping_title}, "tax_account")

if not shipping_account:
frappe.throw("Tax Account not specified for woocommerce shipping method {0}".format(shipping.get("method_title")))
if not 'shipping_account' in locals() or not shipping_account:
shipping_account = default

if not shipping_account:
frappe.throw("Tax Account not specified for woocommerce shipping method {0}".format(shipping_title))

return shipping_account
return shipping_account


def get_tax_account_head(tax):
tax_title = tax.get("name").encode("utf-8") or tax.get("method_title").encode("utf-8")
def get_tax_account_head(tax, default):
tax_title = tax.get("name") or tax.get("method_title")
if tax_title:
tax_account = frappe.db.get_value("woocommerce Tax Account", \
{"parent": "WooCommerce Config", "woocommerce_tax": tax_title}, "tax_account")

tax_account = frappe.db.get_value("woocommerce Tax Account", \
{"parent": "WooCommerce Config", "woocommerce_tax": tax_title}, "tax_account")
if not 'tax_account' in locals() or not tax_account:
tax_account = default

if not tax_account:
frappe.throw("Tax Account not specified for woocommerce Tax {0}".format(tax.get("name")))
frappe.throw("Tax Account not specified for woocommerce Tax {0}".format(tax_title))

return tax_account

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
"section_break_31",
"html_16",
"taxes",
"default_tax_account",
"default_shipping_account",
"section_tax_rules",
"tax_rules",
"section_break_25",
Expand Down Expand Up @@ -285,6 +287,18 @@
"label": "woocommerce Tax Account",
"options": "woocommerce Tax Account"
},
{
"fieldname": "default_tax_account",
"fieldtype": "Link",
"label": "Default Tax Account",
"options": "Account"
},
{
"fieldname": "default_shipping_account",
"fieldtype": "Link",
"label": "Default Shipping Account",
"options": "Account"
},
{
"fieldname": "section_tax_rules",
"fieldtype": "Section Break",
Expand Down