Add test scenario for extended intrastat export
This commit is contained in:
1 parent
a7dba58f95
commit
1be542991a
5 files changed
+148
-16
No files matched your search
@@ -51,7 +51,10 @@ tests_require = [
|
||||
get_require_version('proteus'),
|
||||
get_require_version('trytond_carrier'),
|
||||
get_require_version('trytond_incoterm'),
|
||||
get_require_version('trytond_purchase_shipment_cost'),
|
||||
get_require_version('trytond_stock_consignment'),
|
||||
get_require_version('trytond_stock_package_shipping'),
|
||||
get_require_version('trytond_stock_shipment_cost'),
|
||||
]
|
||||
|
||||
setup(name=name,
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
[
|
||||
{"intrastat_extended": false}
|
||||
,{"intrastat_extended": true}
|
||||
]
|
||||
@@ -10,20 +10,27 @@ Imports::
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> from trytond.modules.account.tests.tools import create_fiscalyear
|
||||
>>> from trytond.modules.company.tests.tools import create_company, get_company
|
||||
>>> from trytond.modules.currency.tests.tools import get_currency
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
>>> intrastat_extended = globals().get('intrastat_extended', False)
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('account_stock_eu')
|
||||
>>> config = activate_modules([
|
||||
... 'account_stock_eu', 'incoterm',
|
||||
... 'stock_shipment_cost', 'purchase_shipment_cost'])
|
||||
|
||||
>>> Carrier = Model.get('carrier')
|
||||
>>> Country = Model.get('country.country')
|
||||
>>> Incoterm = Model.get('incoterm.incoterm')
|
||||
>>> IntrastatDeclaration = Model.get('account.stock.eu.intrastat.declaration')
|
||||
>>> IntrastatDeclarationLine = Model.get(
|
||||
... 'account.stock.eu.intrastat.declaration.line')
|
||||
>>> IntrastatTransport = Model.get('account.stock.eu.intrastat.transport')
|
||||
>>> Organization = Model.get('country.organization')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
@@ -65,11 +72,19 @@ Create company in Belgium::
|
||||
|
||||
>>> _ = create_company(currency=eur)
|
||||
>>> company = get_company()
|
||||
>>> company.incoterms.extend(Incoterm.find())
|
||||
>>> company.save()
|
||||
>>> company_address, = company.party.addresses
|
||||
>>> company_address.country = belgium
|
||||
>>> company_address.subdivision = liege
|
||||
>>> company_address.save()
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = create_fiscalyear(company)
|
||||
>>> fiscalyear.intrastat_extended = intrastat_extended
|
||||
>>> fiscalyear.save()
|
||||
|
||||
Create suppliers::
|
||||
|
||||
>>> supplier_be = Party(name="Supplier BE")
|
||||
@@ -116,6 +131,25 @@ Create product::
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Create carriers::
|
||||
|
||||
>>> carrier_template = ProductTemplate(name="Carrier Product")
|
||||
>>> carrier_template.default_uom = unit
|
||||
>>> carrier_template.type = 'service'
|
||||
>>> carrier_template.list_price = Decimal('5')
|
||||
>>> carrier_template.save()
|
||||
>>> carrier_product, = carrier_template.products
|
||||
|
||||
>>> road_transport, = IntrastatTransport.find([('name', '=', "Road transport")])
|
||||
>>> carrier = Carrier()
|
||||
>>> party = Party(name="Carrier")
|
||||
>>> party.save()
|
||||
>>> carrier.party = party
|
||||
>>> carrier.carrier_product = carrier_product
|
||||
>>> carrier.shipment_cost_allocation_method = 'cost'
|
||||
>>> carrier.intrastat_transport = road_transport
|
||||
>>> carrier.save()
|
||||
|
||||
Get stock locations::
|
||||
|
||||
>>> warehouse_loc, = StockLocation.find([('code', '=', 'WH')])
|
||||
@@ -148,6 +182,10 @@ Receive products from France::
|
||||
|
||||
>>> shipment = ShipmentIn()
|
||||
>>> shipment.supplier = supplier_fr
|
||||
>>> shipment.incoterm, = Incoterm.find([
|
||||
... ('code', '=', 'EXW'), ('version', '=', '2020')])
|
||||
>>> shipment.incoterm_location = supplier_fr.addresses[0]
|
||||
>>> shipment.carrier = carrier
|
||||
>>> move = shipment.incoming_moves.new()
|
||||
>>> move.from_location = shipment.supplier_location
|
||||
>>> move.to_location = shipment.warehouse_input
|
||||
@@ -188,6 +226,7 @@ Receive products from US::
|
||||
|
||||
>>> shipment = ShipmentIn()
|
||||
>>> shipment.supplier = supplier_us
|
||||
>>> shipment.carrier = carrier
|
||||
>>> move = shipment.incoming_moves.new()
|
||||
>>> move.from_location = shipment.supplier_location
|
||||
>>> move.to_location = shipment.warehouse_input
|
||||
@@ -210,6 +249,10 @@ Receive returned products from France::
|
||||
|
||||
>>> shipment = ShipmentOutReturn()
|
||||
>>> shipment.customer = customer_fr
|
||||
>>> shipment.carrier = carrier
|
||||
>>> shipment.incoterm, = Incoterm.find([
|
||||
... ('code', '=', 'FCA'), ('version', '=', '2020')])
|
||||
>>> shipment.incoterm_location = warehouse_loc.address
|
||||
>>> move = shipment.incoming_moves.new()
|
||||
>>> move.from_location = shipment.customer_location
|
||||
>>> move.to_location = shipment.warehouse_input
|
||||
@@ -254,8 +297,7 @@ Check declaration::
|
||||
>>> assertEqual(declaration.month, today.replace(day=1))
|
||||
>>> declaration.state
|
||||
'opened'
|
||||
>>> bool(declaration.extended)
|
||||
False
|
||||
>>> assertEqual(bool(declaration.extended), intrastat_extended)
|
||||
|
||||
>>> with config.set_context(declaration=declaration.id):
|
||||
... declaration_line, _ = IntrastatDeclarationLine.find([])
|
||||
@@ -276,14 +318,22 @@ Check declaration::
|
||||
>>> declaration_line.additional_unit
|
||||
20.0
|
||||
>>> declaration_line.country_of_origin
|
||||
>>> assertEqual(declaration_line.transport, road_transport)
|
||||
>>> declaration_line.incoterm.code
|
||||
'EXW'
|
||||
>>> declaration_line.vat
|
||||
|
||||
Export declaration::
|
||||
|
||||
>>> _ = declaration.click('export')
|
||||
>>> export = Wizard('account.stock.eu.intrastat.declaration.export', [declaration])
|
||||
>>> export.form.file
|
||||
b'19;FR;11;2;9403 10 51;60.0;20.0;1800.00;;\r\n19;FR;21;2;9403 10 51;15.0;5.0;750.00;;\r\n'
|
||||
>>> assertEqual(
|
||||
... export.form.file,
|
||||
... b'19;FR;11;2;9403 10 51;60.0;20.0;1800.00;3;EXW;;\r\n'
|
||||
... b'19;FR;21;2;9403 10 51;15.0;5.0;750.00;3;FCA;;\r\n'
|
||||
... if intrastat_extended else
|
||||
... b'19;FR;11;2;9403 10 51;60.0;20.0;1800.00;;\r\n'
|
||||
... b'19;FR;21;2;9403 10 51;15.0;5.0;750.00;;\r\n')
|
||||
>>> export.form.filename.endswith('.csv')
|
||||
True
|
||||
>>> declaration.state
|
||||
@@ -301,8 +351,13 @@ Export declaration as Spain::
|
||||
>>> zip = zipfile.ZipFile(io.BytesIO(export.form.file))
|
||||
>>> zip.namelist()
|
||||
['arrival-0.csv']
|
||||
>>> zip.open('arrival-0.csv').read()
|
||||
b'FR;2;;11;;;9403 10 51;;;60.0;20.0;1800.00;1800.00;\r\nFR;2;;21;;;9403 10 51;;;15.0;5.0;750.00;750.00;\r\n'
|
||||
>>> assertEqual(
|
||||
... zip.open('arrival-0.csv').read(),
|
||||
... b'FR;2;EXW;11;3;;9403 10 51;;;60.0;20.0;1800.00;1800.00;\r\n'
|
||||
... b'FR;2;FCA;21;3;;9403 10 51;;;15.0;5.0;750.00;750.00;\r\n'
|
||||
... if intrastat_extended else
|
||||
... b'FR;2;;11;;;9403 10 51;;;60.0;20.0;1800.00;1800.00;\r\n'
|
||||
... b'FR;2;;21;;;9403 10 51;;;15.0;5.0;750.00;750.00;\r\n')
|
||||
|
||||
Export declaration as fallback::
|
||||
|
||||
@@ -311,7 +366,12 @@ Export declaration as fallback::
|
||||
|
||||
>>> _ = declaration.click('export')
|
||||
>>> export = Wizard('account.stock.eu.intrastat.declaration.export', [declaration])
|
||||
>>> export.form.file
|
||||
b'arrival,FR,2,9403 10 51,60.0,1800.00,11,20.0,,\r\narrival,FR,2,9403 10 51,15.0,750.00,21,5.0,,\r\n'
|
||||
>>> assertEqual(
|
||||
... export.form.file,
|
||||
... b'arrival,FR,2,9403 10 51,60.0,1800.00,11,20.0,,,3,EXW\r\n'
|
||||
... b'arrival,FR,2,9403 10 51,15.0,750.00,21,5.0,,,3,FCA\r\n'
|
||||
... if intrastat_extended else
|
||||
... b'arrival,FR,2,9403 10 51,60.0,1800.00,11,20.0,,\r\n'
|
||||
... b'arrival,FR,2,9403 10 51,15.0,750.00,21,5.0,,\r\n')
|
||||
>>> export.form.filename.endswith('.csv')
|
||||
True
|
||||
@@ -0,0 +1,4 @@
|
||||
[
|
||||
{"intrastat_extended": false}
|
||||
,{"intrastat_extended": true}
|
||||
]
|
||||
@@ -10,20 +10,27 @@ Imports::
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> from trytond.modules.account.tests.tools import create_fiscalyear
|
||||
>>> from trytond.modules.company.tests.tools import create_company, get_company
|
||||
>>> from trytond.modules.currency.tests.tools import get_currency
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
>>> intrastat_extended = globals().get('intrastat_extended', False)
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('account_stock_eu')
|
||||
>>> config = activate_modules([
|
||||
... 'account_stock_eu', 'incoterm',
|
||||
... 'stock_shipment_cost', 'stock_package_shipping'])
|
||||
|
||||
>>> Carrier = Model.get('carrier')
|
||||
>>> Country = Model.get('country.country')
|
||||
>>> Incoterm = Model.get('incoterm.incoterm')
|
||||
>>> IntrastatDeclaration = Model.get('account.stock.eu.intrastat.declaration')
|
||||
>>> IntrastatDeclarationLine = Model.get(
|
||||
... 'account.stock.eu.intrastat.declaration.line')
|
||||
>>> IntrastatTransport = Model.get('account.stock.eu.intrastat.transport')
|
||||
>>> Organization = Model.get('country.organization')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
@@ -67,11 +74,19 @@ Create company in Belgium::
|
||||
|
||||
>>> _ = create_company(currency=eur)
|
||||
>>> company = get_company()
|
||||
>>> company.incoterms.extend(Incoterm.find())
|
||||
>>> company.save()
|
||||
>>> company_address, = company.party.addresses
|
||||
>>> company_address.country = belgium
|
||||
>>> company_address.subdivision = liege
|
||||
>>> company_address.save()
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = create_fiscalyear(company)
|
||||
>>> fiscalyear.intrastat_extended = intrastat_extended
|
||||
>>> fiscalyear.save()
|
||||
|
||||
Create suppliers::
|
||||
|
||||
>>> customer_be = Party(name="Customer BE")
|
||||
@@ -117,6 +132,25 @@ Create product::
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Create carriers::
|
||||
|
||||
>>> carrier_template = ProductTemplate(name="Carrier Product")
|
||||
>>> carrier_template.default_uom = unit
|
||||
>>> carrier_template.type = 'service'
|
||||
>>> carrier_template.list_price = Decimal('5')
|
||||
>>> carrier_template.save()
|
||||
>>> carrier_product, = carrier_template.products
|
||||
|
||||
>>> road_transport, = IntrastatTransport.find([('name', '=', "Road transport")])
|
||||
>>> carrier = Carrier()
|
||||
>>> party = Party(name="Carrier")
|
||||
>>> party.save()
|
||||
>>> carrier.party = party
|
||||
>>> carrier.carrier_product = carrier_product
|
||||
>>> carrier.shipment_cost_allocation_method = 'cost'
|
||||
>>> carrier.intrastat_transport = road_transport
|
||||
>>> carrier.save()
|
||||
|
||||
Get stock locations::
|
||||
|
||||
>>> warehouse_loc, = StockLocation.find([('code', '=', 'WH')])
|
||||
@@ -127,6 +161,7 @@ Send products to Belgium::
|
||||
|
||||
>>> shipment = ShipmentOut()
|
||||
>>> shipment.customer = customer_be
|
||||
>>> shipment.carrier = carrier
|
||||
>>> move = shipment.outgoing_moves.new()
|
||||
>>> move.from_location = shipment.warehouse_output
|
||||
>>> move.to_location = shipment.customer_location
|
||||
@@ -151,6 +186,10 @@ Send products to particular to France::
|
||||
|
||||
>>> shipment = ShipmentOut()
|
||||
>>> shipment.customer = customer_fr
|
||||
>>> shipment.carrier = carrier
|
||||
>>> shipment.incoterm, = Incoterm.find([
|
||||
... ('code', '=', 'FCA'), ('version', '=', '2020')])
|
||||
>>> shipment.incoterm_location = shipment.delivery_address
|
||||
>>> move = shipment.outgoing_moves.new()
|
||||
>>> move.from_location = shipment.warehouse_output
|
||||
>>> move.to_location = shipment.customer_location
|
||||
@@ -195,6 +234,7 @@ Send products to US::
|
||||
|
||||
>>> shipment = ShipmentOut()
|
||||
>>> shipment.customer = customer_us
|
||||
>>> shipment.carrier = carrier
|
||||
>>> move = shipment.outgoing_moves.new()
|
||||
>>> move.from_location = shipment.warehouse_output
|
||||
>>> move.to_location = shipment.customer_location
|
||||
@@ -220,6 +260,9 @@ Send returned products to France::
|
||||
>>> shipment = ShipmentInReturn()
|
||||
>>> shipment.supplier = supplier_fr
|
||||
>>> shipment.from_location = warehouse_loc.storage_location
|
||||
>>> shipment.carrier = carrier
|
||||
>>> shipment.incoterm, = Incoterm.find([
|
||||
... ('code', '=', 'EXW'), ('version', '=', '2020')])
|
||||
>>> move = shipment.moves.new()
|
||||
>>> move.from_location = shipment.from_location
|
||||
>>> move.to_location = shipment.to_location
|
||||
@@ -287,6 +330,9 @@ Check declaration::
|
||||
'CN'
|
||||
>>> declaration_line.vat.code
|
||||
'FR40303265045'
|
||||
>>> assertEqual(declaration_line.transport, road_transport)
|
||||
>>> declaration_line.incoterm.code
|
||||
'EXW'
|
||||
|
||||
Export declaration::
|
||||
|
||||
@@ -294,8 +340,13 @@ Export declaration::
|
||||
>>> export = Wizard('account.stock.eu.intrastat.declaration.export', [declaration])
|
||||
>>> export.form.filename.endswith('.csv')
|
||||
True
|
||||
>>> export.form.file
|
||||
b'29;FR;12;2;9403 10 51;60.0;20.0;1800.00;CN;\r\n29;FR;21;2;9403 10 51;15.0;5.0;750.00;CN;FR40303265045\r\n'
|
||||
>>> assertEqual(
|
||||
... export.form.file,
|
||||
... b'29;FR;12;2;9403 10 51;60.0;20.0;1800.00;3;FCA;CN;\r\n'
|
||||
... b'29;FR;21;2;9403 10 51;15.0;5.0;750.00;3;EXW;CN;FR40303265045\r\n'
|
||||
... if intrastat_extended else
|
||||
... b'29;FR;12;2;9403 10 51;60.0;20.0;1800.00;CN;\r\n'
|
||||
... b'29;FR;21;2;9403 10 51;15.0;5.0;750.00;CN;FR40303265045\r\n')
|
||||
>>> declaration.state
|
||||
'closed'
|
||||
|
||||
@@ -311,8 +362,13 @@ Export declaration as Spain::
|
||||
>>> zip = zipfile.ZipFile(io.BytesIO(export.form.file))
|
||||
>>> zip.namelist()
|
||||
['dispatch-0.csv']
|
||||
>>> zip.open('dispatch-0.csv').read()
|
||||
b'FR;2;;12;;;9403 10 51;CN;;60.0;20.0;1800.00;1800.00;\r\nFR;2;;21;;;9403 10 51;CN;;15.0;5.0;750.00;750.00;FR40303265045\r\n'
|
||||
>>> assertEqual(
|
||||
... zip.open('dispatch-0.csv').read(),
|
||||
... b'FR;2;FCA;12;3;;9403 10 51;CN;;60.0;20.0;1800.00;1800.00;\r\n'
|
||||
... b'FR;2;EXW;21;3;;9403 10 51;CN;;15.0;5.0;750.00;750.00;FR40303265045\r\n'
|
||||
... if intrastat_extended else
|
||||
... b'FR;2;;12;;;9403 10 51;CN;;60.0;20.0;1800.00;1800.00;\r\n'
|
||||
... b'FR;2;;21;;;9403 10 51;CN;;15.0;5.0;750.00;750.00;FR40303265045\r\n')
|
||||
|
||||
Export declaration as fallback::
|
||||
|
||||
@@ -323,5 +379,10 @@ Export declaration as fallback::
|
||||
>>> export = Wizard('account.stock.eu.intrastat.declaration.export', [declaration])
|
||||
>>> export.form.filename.endswith('.csv')
|
||||
True
|
||||
>>> export.form.file
|
||||
b'dispatch,FR,2,9403 10 51,60.0,1800.00,12,20.0,CN,\r\ndispatch,FR,2,9403 10 51,15.0,750.00,21,5.0,CN,FR40303265045\r\n'
|
||||
>>> assertEqual(
|
||||
... export.form.file,
|
||||
... b'dispatch,FR,2,9403 10 51,60.0,1800.00,12,20.0,CN,,3,FCA\r\n'
|
||||
... b'dispatch,FR,2,9403 10 51,15.0,750.00,21,5.0,CN,FR40303265045,3,EXW\r\n'
|
||||
... if intrastat_extended else
|
||||
... b'dispatch,FR,2,9403 10 51,60.0,1800.00,12,20.0,CN,\r\n'
|
||||
... b'dispatch,FR,2,9403 10 51,15.0,750.00,21,5.0,CN,FR40303265045\r\n')
|
||||
Reference in new issue
Block a user