1 parent
8320379195
commit
f3bcf05446
3 files changed
+53
-5
No files matched your search
@@ -1,2 +1,2 @@
|
||||
id title description link image_link availability price sale_price google_product_category brand condition item_group_id unit_pricing_measure unit_pricing_base_measure product_type gtin mpn is_bundle product_length product_width product_height product_weight shipping
|
||||
12345 Product Description https://example.com/p/12345 https://example.com/i/12345.jpg in stock 10.00 usd Brand new 1ct False 50.0 cm 100.0 cm 20.0 cm 5.0 kg US::Shipping:5.00 usd
|
||||
12345 Product Description https://example.com/p/12345 https://example.com/i/12345.jpg in stock 10.00 usd Brand new 1ct False 50.0 cm 100.0 cm 20.0 cm 5.0 kg US::Shipping:6.00 usd
|
||||
|
@@ -6,6 +6,7 @@ import tempfile
|
||||
from decimal import Decimal
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from trytond.modules.account.tests import create_chart
|
||||
from trytond.modules.company.tests import create_company, set_company
|
||||
from trytond.pool import Pool
|
||||
from trytond.protocols.wrappers import HTTPStatus
|
||||
@@ -22,14 +23,17 @@ class WebShopProductDataFeedTestCase(ModuleTestCase):
|
||||
def test_data_feed(self):
|
||||
"Test data feed"
|
||||
pool = Pool()
|
||||
Account = pool.get('account.account')
|
||||
Carrier = pool.get('carrier')
|
||||
CarrierSelection = pool.get('carrier.selection')
|
||||
Country = pool.get('country.country')
|
||||
Party = pool.get('party.party')
|
||||
Product = pool.get('product.product')
|
||||
ProductCategory = pool.get('product.category')
|
||||
ProductIdentifier = pool.get('product.identifier')
|
||||
ProductTemplate = pool.get('product.template')
|
||||
Shop = pool.get('web.shop')
|
||||
Tax = pool.get('account.tax')
|
||||
UoM = pool.get('product.uom')
|
||||
|
||||
unit, = UoM.search([('name', '=', "Unit")])
|
||||
@@ -45,6 +49,25 @@ class WebShopProductDataFeedTestCase(ModuleTestCase):
|
||||
patch.object(tempfile, 'gettempdir') as gettempdir:
|
||||
gettempdir.return_value = directory
|
||||
|
||||
create_chart(company)
|
||||
|
||||
tax_account, = Account.search([
|
||||
('name', '=', 'Main Tax'),
|
||||
])
|
||||
|
||||
tax = Tax()
|
||||
tax.name = tax.description = 'Test'
|
||||
tax.type = 'percentage'
|
||||
tax.rate = Decimal('0.2')
|
||||
tax.invoice_account = tax_account
|
||||
tax.credit_note_account = tax_account
|
||||
tax.save()
|
||||
|
||||
category = ProductCategory(
|
||||
name='Category', accounting=True,
|
||||
customer_taxes=[tax])
|
||||
category.save()
|
||||
|
||||
carrier_template = ProductTemplate(
|
||||
name="Shipping",
|
||||
type='service',
|
||||
@@ -52,6 +75,7 @@ class WebShopProductDataFeedTestCase(ModuleTestCase):
|
||||
salable=True,
|
||||
sale_uom=unit,
|
||||
list_price=Decimal('5.0000'),
|
||||
account_category=category,
|
||||
)
|
||||
carrier_template.save()
|
||||
carrier_product = Product(template=carrier_template)
|
||||
|
||||
@@ -344,18 +344,42 @@ class Shop_ShipmentCost(metaclass=PoolMeta):
|
||||
return CarrierSelection.get_carriers(pattern)
|
||||
|
||||
def _product_data_feed_carrier_cost(
|
||||
self, product, country, carrier, price):
|
||||
self, product, country, carrier, price, pattern=None):
|
||||
pool = Pool()
|
||||
Currency = pool.get('currency.currency')
|
||||
Date = pool.get('ir.date')
|
||||
Tax = pool.get('account.tax')
|
||||
if pattern is None:
|
||||
pattern = {}
|
||||
|
||||
today = Date.today()
|
||||
context = {}
|
||||
if carrier.carrier_cost_method == 'percentage':
|
||||
context['amount'] = price
|
||||
context['currency'] = self.currency.id
|
||||
with Transaction().set_context(context=context):
|
||||
cost, currency_id = carrier.get_sale_price()
|
||||
if cost is not None:
|
||||
return Currency.compute(
|
||||
Currency(currency_id), cost, self.currency)
|
||||
if cost is None:
|
||||
return
|
||||
customer_tax_rule = self._customer_taxe_rule()
|
||||
taxes = set()
|
||||
for tax in carrier.carrier_product.customer_taxes_used:
|
||||
if customer_tax_rule:
|
||||
tax_ids = customer_tax_rule.apply(tax, pattern)
|
||||
if tax_ids:
|
||||
taxes.update(tax_ids)
|
||||
continue
|
||||
taxes.add(tax.id)
|
||||
if customer_tax_rule:
|
||||
tax_ids = customer_tax_rule.apply(None, pattern)
|
||||
if tax_ids:
|
||||
taxes.update(tax_ids)
|
||||
taxes = Tax.browse(taxes)
|
||||
l_taxes = Tax.compute(taxes, cost, 1, today)
|
||||
for l_tax in l_taxes:
|
||||
cost += l_tax['amount']
|
||||
return Currency.compute(
|
||||
Currency(currency_id), cost, self.currency)
|
||||
|
||||
def _product_data_feed_row(self, product, price, sale_price):
|
||||
row = super()._product_data_feed_row(product, price, sale_price)
|
||||
|
||||
Reference in new issue
Block a user