Allow EU excise declaration in alcohol volume
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval, Id, If
|
||||
|
||||
|
||||
class ExciseTax(metaclass=PoolMeta):
|
||||
__name__ = 'account.stock.eu.excise.tax'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
cls.quantity.selection.append(
|
||||
('ethanol_volume', "Alcohol Volume"))
|
||||
cls.uom.domain = [If(
|
||||
Eval('quantity') == 'ethanol_volume',
|
||||
[('category', '=', Id('product', 'uom_cat_volume'))],
|
||||
cls.uom.domain)]
|
||||
|
||||
def convert_quantity(self, product, quantity):
|
||||
pool = Pool()
|
||||
UoM = pool.get('product.uom')
|
||||
|
||||
converted = super().convert_quantity(product, quantity)
|
||||
if self.quantity == 'ethanol_volume':
|
||||
ethanol_by_volume = product.ethanol_by_volume_used
|
||||
if ethanol_by_volume is not None:
|
||||
if product.default_uom.category == self.uom.category:
|
||||
quantity = quantity * ethanol_by_volume
|
||||
converted = UoM.compute_qty(
|
||||
product.default_uom, quantity, self.uom)
|
||||
elif product.volume is not None:
|
||||
quantity = quantity * product.volume * ethanol_by_volume
|
||||
converted = UoM.compute_qty(
|
||||
product.volume_uom, quantity, self.uom)
|
||||
return converted
|
||||
|
||||
|
||||
class ExciseTaxRate(metaclass=PoolMeta):
|
||||
__name__ = 'account.stock.eu.excise.tax.rate'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
cls.formula.help += ("\n"
|
||||
"-ethanol_by_volume: the percentage of alcohol by volume")
|
||||
|
||||
def _compute_context(self, product, quantity):
|
||||
context = super()._compute_context(product, quantity)
|
||||
ethanol_by_volume = 0
|
||||
if product:
|
||||
ethanol_by_volume = product.ethanol_by_volume_used or 0
|
||||
ethanol_by_volume = Decimal(str(ethanol_by_volume))
|
||||
context['names'] = context['names'].copy()
|
||||
context['names']['ethanol_by_volume'] = ethanol_by_volume
|
||||
return context
|
||||
@@ -1,12 +1,57 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.tests.test_tryton import ModuleTestCase
|
||||
|
||||
from trytond.pool import Pool
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
|
||||
|
||||
class StockEthanolTestCase(ModuleTestCase):
|
||||
"Test Stock Ethanol module"
|
||||
module = 'stock_ethanol'
|
||||
extras = ['product_measurements']
|
||||
extras = ['account_stock_eu_excise', 'product_measurements']
|
||||
|
||||
@with_transaction()
|
||||
def test_convert_quantity(self):
|
||||
"Test convert quantity"
|
||||
pool = Pool()
|
||||
ExciseTax = pool.get('account.stock.eu.excise.tax')
|
||||
Product = pool.get('product.product')
|
||||
UoM = pool.get('product.uom')
|
||||
liter, = UoM.search([('name', '=', "Liter")])
|
||||
|
||||
excise_tax = ExciseTax(
|
||||
quantity='ethanol_volume',
|
||||
uom=liter,
|
||||
)
|
||||
product = Product(
|
||||
ethanol_by_volume_used=.2,
|
||||
default_uom=liter,
|
||||
)
|
||||
|
||||
self.assertEqual(excise_tax.convert_quantity(product, 10), 2)
|
||||
|
||||
@with_transaction()
|
||||
def test_convert_quantity_volume(self):
|
||||
"Test convert quantity volume"
|
||||
pool = Pool()
|
||||
ExciseTax = pool.get('account.stock.eu.excise.tax')
|
||||
Product = pool.get('product.product')
|
||||
UoM = pool.get('product.uom')
|
||||
liter, = UoM.search([('name', '=', "Liter")])
|
||||
unit, = UoM.search([('name', '=', "Unit")])
|
||||
|
||||
excise_tax = ExciseTax(
|
||||
quantity='ethanol_volume',
|
||||
uom=liter,
|
||||
)
|
||||
product = Product(
|
||||
ethanol_by_volume_used=.2,
|
||||
default_uom=unit,
|
||||
volume=.5,
|
||||
volume_uom=liter,
|
||||
)
|
||||
|
||||
self.assertEqual(excise_tax.convert_quantity(product, 10), 1)
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
|
||||
@@ -6,6 +6,7 @@ depends:
|
||||
product
|
||||
stock
|
||||
extras_depend:
|
||||
account_stock_eu_excise
|
||||
product_measurements
|
||||
xml:
|
||||
product.xml
|
||||
@@ -20,3 +21,8 @@ model:
|
||||
stock.ConfigurationEthanol
|
||||
stock.Move
|
||||
stock.ProductsByLocations
|
||||
|
||||
[register account_stock_eu_excise]
|
||||
model:
|
||||
account_stock_eu.ExciseTax
|
||||
account_stock_eu.ExciseTaxRate
|
||||
|
||||
Reference in New Issue
Block a user