Fill tax rule pattern of web shop with countries
When account_tax_rule_country is activated, the pattern must be filled with from_country and to_country to compute the right tax. Closes #13223
This commit is contained in:
@@ -32,3 +32,6 @@ def register():
|
||||
Pool.register(
|
||||
web.Shop_PriceList,
|
||||
module='web_shop', type_='model', depends=['sale_price_list'])
|
||||
Pool.register(
|
||||
web.Shop_TaxRuleCountry,
|
||||
module='web_shop', type_='model', depends=['account_tax_rule_country'])
|
||||
|
||||
@@ -51,6 +51,7 @@ for dep in info.get('depends', []):
|
||||
requires.append(get_require_version('trytond'))
|
||||
|
||||
tests_require = [
|
||||
get_require_version('trytond_account_tax_rule_country'),
|
||||
get_require_version('trytond_product_attribute'),
|
||||
get_require_version('trytond_product_image'),
|
||||
get_require_version('trytond_sale_price_list'),
|
||||
|
||||
@@ -8,7 +8,9 @@ from trytond.tests.test_tryton import ModuleTestCase
|
||||
class WebShopTestCase(CompanyTestMixin, ModuleTestCase):
|
||||
'Test Web Shop module'
|
||||
module = 'web_shop'
|
||||
extras = ['product_attribute', 'product_image', 'sale_price_list']
|
||||
extras = [
|
||||
'account_tax_rule_country', 'product_attribute', 'product_image',
|
||||
'sale_price_list']
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
|
||||
@@ -11,6 +11,7 @@ depends:
|
||||
stock
|
||||
web_user
|
||||
extras_depend:
|
||||
account_tax_rule_country
|
||||
product_attribute
|
||||
product_image
|
||||
sale_price_list
|
||||
|
||||
@@ -297,6 +297,22 @@ class Shop_PriceList(metaclass=PoolMeta):
|
||||
return sale
|
||||
|
||||
|
||||
class Shop_TaxRuleCountry(metaclass=PoolMeta):
|
||||
__name__ = 'web.shop'
|
||||
|
||||
def get_products(self, pattern=None):
|
||||
pattern = pattern.copy() if pattern is not None else {}
|
||||
if (self.warehouse
|
||||
and self.warehouse.address
|
||||
and self.warehouse.address.country):
|
||||
pattern.setdefault(
|
||||
'from_country', self.warehouse.address.country.id)
|
||||
else:
|
||||
pattern.setdefault('from_country')
|
||||
pattern.setdefault('to_country')
|
||||
return super().get_products(pattern=pattern)
|
||||
|
||||
|
||||
class Shop_Warehouse(ModelSQL):
|
||||
"Web Shop - Warehouse"
|
||||
__name__ = 'web.shop-stock.location'
|
||||
|
||||
@@ -29,3 +29,7 @@ def register():
|
||||
web.Shop_ShipmentCost,
|
||||
module='web_shop_product_data_feed', type_='model',
|
||||
depends=['sale_shipment_cost'])
|
||||
Pool.register(
|
||||
web.Shop_TaxRuleCountry,
|
||||
module='web_shop_product_data_feed', type_='model',
|
||||
depends=['account_tax_rule_country'])
|
||||
|
||||
@@ -51,6 +51,7 @@ for dep in info.get('depends', []):
|
||||
requires.append(get_require_version('trytond'))
|
||||
|
||||
tests_require = [
|
||||
get_require_version('trytond_account_tax_rule_country'),
|
||||
get_require_version('trytond_product_kit'),
|
||||
get_require_version('trytond_product_measurements'),
|
||||
get_require_version('trytond_sale_shipment_cost'),
|
||||
|
||||
@@ -17,7 +17,9 @@ from trytond.tests.test_tryton import (
|
||||
class WebShopProductDataFeedTestCase(ModuleTestCase):
|
||||
"Test Web Shop Product Data Feed module"
|
||||
module = 'web_shop_product_data_feed'
|
||||
extras = ['product_kit', 'product_measurements', 'sale_shipment_cost']
|
||||
extras = [
|
||||
'account_tax_rule_country', 'product_kit', 'product_measurements',
|
||||
'sale_shipment_cost']
|
||||
|
||||
@with_transaction()
|
||||
def test_data_feed(self):
|
||||
|
||||
@@ -5,6 +5,7 @@ depends:
|
||||
product
|
||||
web_shop
|
||||
extras_depend:
|
||||
account_tax_rule_country
|
||||
product_kit
|
||||
product_measurements
|
||||
sale_shipment_cost
|
||||
|
||||
@@ -396,3 +396,21 @@ class Shop_ShipmentCost(metaclass=PoolMeta):
|
||||
f'{cost} {self.currency.code}')
|
||||
row['shipping'] = ','.join(shipping)
|
||||
return row
|
||||
|
||||
|
||||
class Shop_TaxRuleCountry(metaclass=PoolMeta):
|
||||
__name__ = 'web.shop'
|
||||
|
||||
def _product_data_feed_carrier_cost(
|
||||
self, product, country, carrier, price, pattern=None):
|
||||
pattern = pattern.copy() if pattern is not None else {}
|
||||
if (self.warehouse
|
||||
and self.warehouse.address
|
||||
and self.warehouse.address.country):
|
||||
pattern.setdefault(
|
||||
'from_country', self.warehouse.address.country.id)
|
||||
else:
|
||||
pattern.setdefault('from_country')
|
||||
pattern.setdefault('to_country', country.id)
|
||||
return super()._product_data_feed_carrier_cost(
|
||||
product, country, carrier, price, pattern=pattern)
|
||||
|
||||
Reference in New Issue
Block a user