Commit f5321a6d authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_advanced_ecommerce: handle multiple tax

parent 530fabec
......@@ -10,14 +10,47 @@ if result_type != 'edit':
# Update data
kw, _ = result
vat_code = kw.pop('vat_code', None)
turnover = kw.pop('turnover', None)
context.WebSite_executeMethodAsSuperUser('edit', **kw)
#context.edit(**kw)
result, result_type = context.Base_edit('Person_viewAsWeb', silent_mode=1, field_prefix='your_')
if result_type != 'edit':
return result # XXX add support for editable in this call
# Update data
kw, _ = result
vat_code = kw.pop('vat_code', None)
turnover = kw.pop('turnover', None)
if vat_code:
subordination = context.getCareerSubordinationValue()
if not subordination:
subordination = context.organisation_module.newContent(portal_type='Organisation')
context.edit(career_subordination_value = subordination)
if subordination.getValidationState() in ('invalidated', 'draft'):
subordination.validate()
subordination.edit(
vat_code=vat_code,
turnover = turnover
)
else:
subordination = context.getCareerSubordinationValue()
if subordination and subordination.getValidationState() == 'validated':
subordination.invalidate()
subordination.edit(
vat_code='',
turnover = ''
)
login_come_from_url = context.REQUEST.get("field_your_login_come_from_url")
edit_portal_status_message = context.REQUEST.get("field_your_edit_portal_status_message",
translateString("Your personal informations are now updated."))
if login_come_from_url is not None:
from ZTUtils import make_query
query = make_query({'portal_status_message': edit_portal_status_message})
......
......@@ -57,6 +57,7 @@
<value>
<tuple>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
......
......@@ -90,6 +90,8 @@
<string>my_first_name</string>
<string>my_last_name</string>
<string>loyalty_number</string>
<string>your_turnover</string>
<string>your_vat_code</string>
</list>
</value>
</item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>default</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_turnover</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_float_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Turnover(only if you\'re an organisation)</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: here.WebSite_getOrganisationInfo(\'turnover\')</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>default</string>
<string>display_width</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_vat_code</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>display_width</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_width</string> </key>
<value> <int>20</int> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_string_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Vat Code(only if you\\\'re an organisation)</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: here.WebSite_getOrganisationInfo(\'vat_code\')</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
total_discount = context.SaleOrder_getTotalDiscount()
total_tax = context.SaleOrder_getTotalTax()
return context.getTotalPrice() + total_discount + total_tax
if context.ERP5Site_getAuthenticatedMemberPersonValue():
return context.getTotalPrice() + total_discount + total_tax
return context.getTotalPrice() + total_discount
......@@ -17,7 +17,11 @@ if sale_order is None:
if discount:
total = sale_order.SaleOrder_getFinalPrice()
else:
total = sale_order.getTotalPrice() + sale_order.SaleOrder_getTotalTax()
if context.ERP5Site_getAuthenticatedMemberPersonValue():
total = sale_order.getTotalPrice() + context.SaleOrder_getTotalTax()
else:
total = sale_order.getTotalPrice()
if not include_shipping:
shipping_method = getattr(sale_order, 'shipping_method', None)
......
return round(sum([i.getTotalPrice() for i in context.getAggregatedAmountList(rounding=True)
ratio = None
ceiling = None
specialise_value = context.getSpecialiseValue()
while specialise_value.getPortalType() == 'Sale Trade Condition':
tml = specialise_value.contentValues(portal_type='Trade Model Line')
if tml:
ratio = tml[0].getPrice()
ceiling = tml[0].getProperty('ceiling', None)
break
specialise_value = specialise_value.getSpecialiseValue()
total_tax = round(sum([i.getTotalPrice() for i in context.getAggregatedAmountList(rounding=True)
if "base_amount/trade/base/taxable/vat/vat_normal_rate" in i.getBaseApplicationList()]), 2)
if ceiling and total_tax > ceiling:
return ceiling
return total_tax
<tal:block tal:define="dummy here/WebSection_updateShoppingCartAccordingToUserIfNeeded;" />
<tal:block tal:define="shopping_cart here/SaleOrder_getShoppingCart;
web_site here/getWebSiteValue;
portal_path python:web_site.absolute_url();
current_url request/URL;
currency_code web_site/WebSite_getShoppingCartDefaultCurrencyCode;
shopping_cart_item_list shopping_cart/SaleOrder_getShoppingCartItemList;
shipping here/SaleOrder_getSelectedShippingResource;
......@@ -67,7 +71,16 @@
<table cellpadding="0" cellspacing="0">
<tr>
<td><span tal:replace="python: here.Base_translateString('Tax')"/></td>
<tal:block tal:condition="python: here.ERP5Site_getAuthenticatedMemberPersonValue()">
<td> <span tal:replace="python: '%s %s' % (total_tax, currency_code)"/> </td>
</tal:block>
<tal:block tal:condition="python: not here.ERP5Site_getAuthenticatedMemberPersonValue()">
<td>
<a href="#" tal:attributes="href string:${portal_path}/login_form?came_from=${current_url}" >
<span tal:replace="python: here.Base_translateString('Tax will be displayed after login')"/>
</a>
</td>
</tal:block>
</tr>
<tr>
<td><span tal:replace="python: here.Base_translateString('Sub Total')"/></td>
......
<!-- We must change the way we get the currency on sale order -->
<table>
<tal:block tal:define="dummy here/WebSection_updateShoppingCartAccordingToUserIfNeeded;" />
<tal:block tal:define="shopping_cart here/SaleOrder_getShoppingCart;
shopping_cart_item_list here/SaleOrder_getShoppingCartItemList;
web_site here/getWebSiteValue;
portal_path python:web_site.absolute_url();
current_url request/URL;
empty_cart here/SaleOrder_isShoppingCartEmpty;
discount shopping_cart/SaleOrder_getTotalDiscount;
currency web_site/WebSite_getShoppingCartDefaultCurrency;
......@@ -59,14 +62,23 @@
</td></tr>
</tal:block>
<tal:block tal:condition = "python: not empty_cart and total_tax > 0">
<tal:block tal:condition = "python: not empty_cart">
<tr><td class="cart_middle">
<div class="cart_left">
<span tal:replace="python: here.Base_translateString('Tax')"/>
</div>
<tal:block tal:condition="python: here.ERP5Site_getAuthenticatedMemberPersonValue()">
<div class="cart_right">
<span tal:replace="total_tax"/> <span tal:replace="currency_symbol"/>
</div>
</tal:block>
<tal:block tal:condition="python: not here.ERP5Site_getAuthenticatedMemberPersonValue()">
<div class="cart_right">
<a href="#" tal:attributes="href string:${portal_path}/login_form?came_from=${current_url}" >
<span tal:replace="python: here.Base_translateString('Tax will be displayed after login')"/>
</a>
</div>
</tal:block>
</td></tr>
</tal:block>
......
......@@ -16,7 +16,7 @@ sale_order = portal.portal_catalog.getResultValue(
portal_type="Sale Order",
reference=shopping_cart.getReference())
if sale_order.getSimulationState() == "draft":
if sale_order and sale_order.getSimulationState() == "draft":
# Sometimes paypal replies too fast, and order is already ordered already
# When users returns to the portal.
sale_order.WebSite_executeMethodAsSuperUser('cancel', **{'comment':"Sale Order cancelled because: %s" % reason})
......
if not context.ERP5Site_getAuthenticatedMemberPersonValue():
return
shopping_cart = context.SaleOrder_getShoppingCart()
context.WebSection_updateShoppingCartTradeCondition(shopping_cart, None)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>WebSection_updateShoppingCartAccordingToUserIfNeeded</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -17,9 +17,47 @@ if context.REQUEST.get("loyalty_reward", "") == "enable" and context.getSiteLoya
if payment_mode:
reference = '%s_%s' % (reference, payment_mode.lower())
sale_trade_condition = portal.portal_catalog.getResultValue(
shopping_cart.edit(save_payment_mode = payment_mode.lower())
elif shopping_cart.getProperty('save_payment_mode', None):
payment_mode = shopping_cart.getProperty('save_payment_mode', None)
reference = '%s_%s' % (reference, payment_mode)
user = context.ERP5Site_getAuthenticatedMemberPersonValue()
if user:
region_list = user.getDefaultAddressRegion().split('/')
organisation = user.getCareerSubordinationValue()
if payment_mode == 'wechat':
reference = '%s_generale' % reference
else:
if organisation and organisation.getValidationState() == 'validated':
if region_list[0] != 'europe':
reference = '%s_no_europe_company' % reference
else:
if region_list[-1] == 'russian_federation':
reference = '%s_russian_federation_company' % reference
elif region_list[-1] == 'france':
reference = '%s_france_company' % reference
else:
if organisation.getTurnover() < 10000:
reference = '%s_%s_company' % (reference, region_list[-1])
else:
reference = '%s_europe_company' % reference
else:
if region_list[0] != 'europe':
reference = '%s_no_europe_individual' % reference
else:
if region_list[-1] == 'russian_federation':
reference = '%s_russian_federation_individual' % reference
elif region_list[-1] == 'france':
reference = '%s_france_individual' % reference
else:
reference = '%s_europe_individual' % reference
sale_trade_condition = context.portal_catalog.getResultValue(
portal_type='Sale Trade Condition',
reference='%' + reference + '%',
reference=reference,
validation_state='published',
limit=1,
sort_on=(('version', 'descending'),))
......
......@@ -21,6 +21,9 @@ person_role = 'client'
reference = kw.pop('reference')
password = kw.pop('password')
kw.pop('password_confirm', None)
vat_code = kw.pop('vat_code', None)
turnover = kw.pop('turnover', None)
# Check that user doesn't already exists
person_list = [x for x in portal.acl_users.searchUsers(login=reference, exact_match=True) if 'path' in x]
......@@ -52,7 +55,16 @@ person.WebSite_immediateReindex()
login.WebSite_immediateReindex()
person.WebSite_executeMethodAsSuperUser('edit', **kw)
if vat_code:
organisation = portal.organisation_module.newContent(
portal_type='Organisation'
)
organisation.edit(
vat_code=vat_code,
turnover=turnover
)
organisation.validate()
person.edit(career_subordination_value = organisation)
is_shopping_cart = context.REQUEST.get('is_shopping_cart')
if is_shopping_cart is None:
......
organisation = context.ERP5Site_getAuthenticatedMemberPersonValue().getCareerSubordinationValue()
return organisation.getProperty(param, '')
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>param, **kw</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>WebSite_getOrganisationInfo</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -68,6 +68,8 @@
<string>your_came_from</string>
<string>your_is_loyalty_section</string>
<string>your_is_shopping_cart</string>
<string>your_turnover</string>
<string>your_vat_code</string>
</list>
</value>
</item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>default</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_turnover</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_float_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Turnover(only if you\'re an organisation)</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>default</string>
<string>display_width</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_vat_code</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_width</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>display_width</string> </key>
<value> <int>20</int> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_string_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Vat Code(only if you\\\'re an organisation)</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment