first commit
This commit is contained in:
2
modules/stock_package_shipping_ups/tests/__init__.py
Normal file
2
modules/stock_package_shipping_ups/tests/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,234 @@
|
||||
========================================
|
||||
Stock Package Shipping with UPS scenario
|
||||
========================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import os
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.account.tests.tools import (
|
||||
... create_chart, create_fiscalyear, get_accounts)
|
||||
>>> from trytond.modules.account_invoice.tests.tools import (
|
||||
... create_payment_term, set_fiscalyear_invoice_sequences)
|
||||
>>> from trytond.modules.company.tests.tools import create_company, get_company
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... ['stock_package_shipping_ups', 'sale', 'sale_shipment_cost'],
|
||||
... create_company, create_chart)
|
||||
|
||||
Get company::
|
||||
|
||||
>>> company = get_company()
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(create_fiscalyear())
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> revenue = accounts['revenue']
|
||||
>>> expense = accounts['expense']
|
||||
|
||||
Create a payment term::
|
||||
|
||||
>>> payment_term = create_payment_term()
|
||||
>>> payment_term.save()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> Country = Model.get('country.country')
|
||||
|
||||
>>> belgium = Country(code='BE', name='Belgium')
|
||||
>>> belgium.save()
|
||||
>>> france = Country(code='FR', name='France')
|
||||
>>> france.save()
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.save()
|
||||
>>> customer_address = customer.addresses.new()
|
||||
>>> customer_address.street = 'Champs élysées'
|
||||
>>> customer_address.postal_code = '75008'
|
||||
>>> customer_address.city = 'Paris'
|
||||
>>> customer_address.country = france
|
||||
>>> customer_address.save()
|
||||
>>> customer_phone = customer.contact_mechanisms.new()
|
||||
>>> customer_phone.type = 'phone'
|
||||
>>> customer_phone.value = '+33 93 842 8862'
|
||||
>>> customer_phone.save()
|
||||
>>> customer_email = customer.contact_mechanisms.new()
|
||||
>>> customer_email.type = 'email'
|
||||
>>> customer_email.value = 'customer@example.com'
|
||||
>>> customer_email.save()
|
||||
|
||||
Set the warehouse address::
|
||||
|
||||
>>> Address = Model.get('party.address')
|
||||
>>> Location = Model.get('stock.location')
|
||||
>>> warehouse, = Location.find([('type', '=', 'warehouse')])
|
||||
>>> company_address = Address()
|
||||
>>> company_address.party = company.party
|
||||
>>> company_address.street = '2 rue de la Centrale'
|
||||
>>> company_address.postal_code = '4000'
|
||||
>>> company_address.city = 'Sclessin'
|
||||
>>> company_address.country = belgium
|
||||
>>> company_address.save()
|
||||
>>> company_phone = company.party.contact_mechanisms.new()
|
||||
>>> company_phone.type = 'phone'
|
||||
>>> company_phone.value = '+32 4 2522122'
|
||||
>>> company_phone.save()
|
||||
>>> warehouse.address = company_address
|
||||
>>> warehouse.save()
|
||||
|
||||
Get some units::
|
||||
|
||||
>>> UoM = Model.get('product.uom')
|
||||
>>> cm, = UoM.find([('symbol', '=', 'cm')])
|
||||
>>> g, = UoM.find([('symbol', '=', 'g')])
|
||||
|
||||
Create account category::
|
||||
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> account_category = ProductCategory(name="Account Category")
|
||||
>>> account_category.accounting = True
|
||||
>>> account_category.account_expense = expense
|
||||
>>> account_category.account_revenue = revenue
|
||||
>>> account_category.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'product'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.salable = True
|
||||
>>> template.weight = 100
|
||||
>>> template.weight_uom = g
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Create an Inventory::
|
||||
|
||||
>>> Inventory = Model.get('stock.inventory')
|
||||
>>> storage, = Location.find([
|
||||
... ('code', '=', 'STO'),
|
||||
... ])
|
||||
>>> inventory = Inventory()
|
||||
>>> inventory.location = storage
|
||||
>>> inventory_line = inventory.lines.new(product=product)
|
||||
>>> inventory_line.quantity = 100.0
|
||||
>>> inventory_line.expected_quantity = 0.0
|
||||
>>> inventory.click('confirm')
|
||||
>>> inventory.state
|
||||
'done'
|
||||
|
||||
Create Package Type::
|
||||
|
||||
>>> PackageType = Model.get('stock.package.type')
|
||||
>>> ups_box = PackageType(
|
||||
... name='UPS Box', ups_code='02',
|
||||
... length=10, length_uom=cm,
|
||||
... height=8, height_uom=cm,
|
||||
... width=1, width_uom=cm)
|
||||
>>> ups_box.save()
|
||||
|
||||
Create a UPS Carrier and the related credential::
|
||||
|
||||
>>> Carrier = Model.get('carrier')
|
||||
>>> CarrierSelection = Model.get('carrier.selection')
|
||||
>>> UPSCredential = Model.get('carrier.credential.ups')
|
||||
|
||||
>>> credential = UPSCredential()
|
||||
>>> credential.company = company
|
||||
>>> credential.client_id = os.getenv('UPS_CLIENT_ID')
|
||||
>>> credential.client_secret = os.getenv('UPS_CLIENT_SECRET')
|
||||
>>> credential.account_number = os.getenv('UPS_ACCOUNT_NUMBER')
|
||||
>>> credential.server = 'testing'
|
||||
>>> credential.save()
|
||||
|
||||
>>> carrier_product_template = ProductTemplate()
|
||||
>>> carrier_product_template.name = 'UPS Ground'
|
||||
>>> carrier_product_template.default_uom = unit
|
||||
>>> carrier_product_template.type = 'service'
|
||||
>>> carrier_product_template.salable = True
|
||||
>>> carrier_product_template.list_price = Decimal(20)
|
||||
>>> carrier_product_template.account_category = account_category
|
||||
>>> carrier_product_template.save()
|
||||
>>> carrier_product, = carrier_product_template.products
|
||||
|
||||
>>> ups = Party(name='UPS')
|
||||
>>> ups.save()
|
||||
|
||||
>>> carrier = Carrier()
|
||||
>>> carrier.party = ups
|
||||
>>> carrier.carrier_product = carrier_product
|
||||
>>> carrier.shipping_service = 'ups'
|
||||
>>> carrier.ups_service_type = '11'
|
||||
>>> carrier.ups_label_image_format = 'GIF'
|
||||
>>> carrier.ups_notifications = ['5', '7', '012']
|
||||
>>> carrier.save()
|
||||
|
||||
>>> catchall_selection = CarrierSelection(carrier=carrier)
|
||||
>>> catchall_selection.save()
|
||||
|
||||
Create a sale and thus a shipment::
|
||||
|
||||
>>> Sale = Model.get('sale.sale')
|
||||
>>> SaleLine = Model.get('sale.line')
|
||||
>>> sale = Sale()
|
||||
>>> sale.party = customer
|
||||
>>> sale.shipment_address = customer_address
|
||||
>>> sale.payment_term = payment_term
|
||||
>>> sale.invoice_method = 'order'
|
||||
>>> sale.carrier = carrier
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product
|
||||
>>> sale_line.quantity = 2.0
|
||||
>>> sale.click('quote')
|
||||
>>> sale.click('confirm')
|
||||
>>> sale.click('process')
|
||||
|
||||
Create the packs and ship the shipment::
|
||||
|
||||
>>> Package = Model.get('stock.package')
|
||||
>>> shipment, = sale.shipments
|
||||
>>> shipment.click('assign_try')
|
||||
>>> shipment.click('pick')
|
||||
>>> pack = shipment.packages.new()
|
||||
>>> pack.type = ups_box
|
||||
>>> pack_move, = pack.moves.find([])
|
||||
>>> pack.moves.append(pack_move)
|
||||
>>> shipment.click('pack')
|
||||
|
||||
>>> create_shipping = shipment.click('create_shipping')
|
||||
>>> shipment.reload()
|
||||
>>> bool(shipment.shipping_reference)
|
||||
True
|
||||
>>> pack, = shipment.root_packages
|
||||
>>> pack.shipping_label is not None
|
||||
True
|
||||
>>> pack.shipping_label_mimetype
|
||||
'image/gif'
|
||||
>>> pack.shipping_reference is not None
|
||||
True
|
||||
>>> pack.shipping_tracking_url
|
||||
'https://www.ups.com/track?...'
|
||||
>>> pack.shipping_reference in pack.shipping_tracking_url
|
||||
True
|
||||
|
||||
Because there is only one box, the pack shipping number is also the shipment
|
||||
identification number::
|
||||
|
||||
>>> assertEqual(pack.shipping_reference, shipment.shipping_reference)
|
||||
@@ -0,0 +1,187 @@
|
||||
======================================================
|
||||
Stock Package Shipping with UPS International Scenario
|
||||
======================================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import os
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.company.tests.tools import create_company, get_company
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... ['stock_package_shipping_ups', 'stock_shipment_customs'],
|
||||
... create_company)
|
||||
|
||||
>>> Agent = Model.get('customs.agent')
|
||||
>>> AgentSelection = Model.get('customs.agent.selection')
|
||||
>>> Address = Model.get('party.address')
|
||||
>>> Carrier = Model.get('carrier')
|
||||
>>> Country = Model.get('country.country')
|
||||
>>> Location = Model.get('stock.location')
|
||||
>>> Package = Model.get('stock.package')
|
||||
>>> PackageType = Model.get('stock.package.type')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> Shipment = Model.get('stock.shipment.out')
|
||||
>>> UPSCredential = Model.get('carrier.credential.ups')
|
||||
>>> UoM = Model.get('product.uom')
|
||||
|
||||
Get company::
|
||||
|
||||
>>> company = get_company()
|
||||
|
||||
Create countries::
|
||||
|
||||
>>> belgium = Country(code='BE', name="Belgium")
|
||||
>>> belgium.save()
|
||||
>>> switzerland = Country(code='CH', name="Switerland")
|
||||
>>> switzerland.save()
|
||||
>>> taiwan = Country(code='TW', name="Taiwan")
|
||||
>>> taiwan.save()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> customer = Party(name="Customer")
|
||||
>>> customer_address, = customer.addresses
|
||||
>>> customer_address.street = "Pfistergasse 17"
|
||||
>>> customer_address.postal_code = "6003"
|
||||
>>> customer_address.city = "Lucerna"
|
||||
>>> customer_address.country = switzerland
|
||||
>>> customer_phone = customer.contact_mechanisms.new()
|
||||
>>> customer_phone.type = 'phone'
|
||||
>>> customer_phone.value = "+(41) (041) 410-62-66"
|
||||
>>> customer_email = customer.contact_mechanisms.new()
|
||||
>>> customer_email.type = 'email'
|
||||
>>> customer_email.value = 'customer@example.com'
|
||||
>>> customer.save()
|
||||
|
||||
>>> agent_party = Party(name="Agent")
|
||||
>>> agent_address, = agent_party.addresses
|
||||
>>> agent_address.street = "Gerechtigkeitsgasse 53"
|
||||
>>> agent_address.postal_code = "3011"
|
||||
>>> agent_address.city = "Berna"
|
||||
>>> agent_address.country = switzerland
|
||||
>>> agent_identifier = agent_party.identifiers.new()
|
||||
>>> agent_identifier.type = 'ch_vat'
|
||||
>>> agent_identifier.code = "CHE-123.456.788 IVA"
|
||||
>>> agent_party.save()
|
||||
>>> agent = Agent(party=agent_party)
|
||||
>>> agent.save()
|
||||
>>> AgentSelection(to_country=switzerland, agent=agent).save()
|
||||
|
||||
Set the warehouse address::
|
||||
|
||||
>>> warehouse, = Location.find([('type', '=', 'warehouse')])
|
||||
>>> company_address = Address()
|
||||
>>> company_address.party = company.party
|
||||
>>> company_address.street = '2 rue de la Centrale'
|
||||
>>> company_address.postal_code = '4000'
|
||||
>>> company_address.city = 'Sclessin'
|
||||
>>> company_address.country = belgium
|
||||
>>> company_address.save()
|
||||
>>> company_phone = company.party.contact_mechanisms.new()
|
||||
>>> company_phone.type = 'phone'
|
||||
>>> company_phone.value = '+32 4 2522122'
|
||||
>>> company_phone.save()
|
||||
>>> warehouse.address = company_address
|
||||
>>> warehouse.save()
|
||||
|
||||
Get some units::
|
||||
|
||||
>>> unit, = UoM.find([('name', '=', "Unit")], limit=1)
|
||||
>>> cm, = UoM.find([('name', '=', "Centimeter")], limit=1)
|
||||
>>> gram, = UoM.find([('name', '=', "Gram")], limit=1)
|
||||
|
||||
Create product::
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "Product"
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.weight = 100
|
||||
>>> template.weight_uom = gram
|
||||
>>> template.list_price = Decimal('10.0000')
|
||||
>>> template.country_of_origin = taiwan
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Create Package Type::
|
||||
|
||||
>>> ups_box = PackageType(
|
||||
... name='UPS Box', ups_code='02',
|
||||
... length=10, length_uom=cm,
|
||||
... height=8, height_uom=cm,
|
||||
... width=1, width_uom=cm)
|
||||
>>> ups_box.save()
|
||||
|
||||
Create a UPS Carrier and the related credential::
|
||||
|
||||
>>> credential = UPSCredential()
|
||||
>>> credential.company = company
|
||||
>>> credential.client_id = os.getenv('UPS_CLIENT_ID')
|
||||
>>> credential.client_secret = os.getenv('UPS_CLIENT_SECRET')
|
||||
>>> credential.account_number = os.getenv('UPS_ACCOUNT_NUMBER')
|
||||
>>> credential.server = 'testing'
|
||||
>>> credential.use_international_forms = True
|
||||
>>> credential.save()
|
||||
|
||||
>>> carrier_product_template = ProductTemplate()
|
||||
>>> carrier_product_template.name = 'UPS Ground'
|
||||
>>> carrier_product_template.default_uom = unit
|
||||
>>> carrier_product_template.type = 'service'
|
||||
>>> carrier_product_template.list_price = Decimal(20)
|
||||
>>> carrier_product_template.save()
|
||||
>>> carrier_product, = carrier_product_template.products
|
||||
|
||||
>>> ups = Party(name='UPS')
|
||||
>>> ups.save()
|
||||
|
||||
>>> carrier = Carrier()
|
||||
>>> carrier.party = ups
|
||||
>>> carrier.carrier_product = carrier_product
|
||||
>>> carrier.shipping_service = 'ups'
|
||||
>>> carrier.ups_service_type = '65'
|
||||
>>> carrier.ups_label_image_format = 'GIF'
|
||||
>>> carrier.ups_notifications = ['5', '7', '012']
|
||||
>>> carrier.save()
|
||||
|
||||
Create a shipment::
|
||||
|
||||
>>> shipment = Shipment()
|
||||
>>> shipment.customer = customer
|
||||
>>> shipment.carrier = carrier
|
||||
>>> shipment.shipping_description = "Shipping description"
|
||||
>>> move = shipment.outgoing_moves.new()
|
||||
>>> move.product = product
|
||||
>>> move.unit = unit
|
||||
>>> move.quantity = 2
|
||||
>>> move.from_location = shipment.warehouse_output
|
||||
>>> move.to_location = shipment.customer_location
|
||||
>>> move.unit_price = Decimal('50.0000')
|
||||
>>> move.currency = company.currency
|
||||
>>> shipment.click('wait')
|
||||
>>> assertEqual(shipment.customs_agent, agent)
|
||||
>>> shipment.click('assign_force')
|
||||
>>> shipment.click('pick')
|
||||
>>> shipment.state
|
||||
'picked'
|
||||
|
||||
Create the packs and ship the shipment::
|
||||
|
||||
>>> pack = shipment.packages.new()
|
||||
>>> pack.type = ups_box
|
||||
>>> pack_move, = pack.moves.find([])
|
||||
>>> pack.moves.append(pack_move)
|
||||
>>> shipment.click('pack')
|
||||
>>> shipment.state
|
||||
'packed'
|
||||
|
||||
>>> create_shipping = shipment.click('create_shipping')
|
||||
>>> shipment.reload()
|
||||
>>> bool(shipment.shipping_reference)
|
||||
True
|
||||
13
modules/stock_package_shipping_ups/tests/test_module.py
Normal file
13
modules/stock_package_shipping_ups/tests/test_module.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# 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
|
||||
|
||||
|
||||
class ShippingUpsTestCase(ModuleTestCase):
|
||||
'Test Shipping Ups module'
|
||||
module = 'stock_package_shipping_ups'
|
||||
extras = ['customs', 'incoterm', 'stock_shipment_customs']
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
18
modules/stock_package_shipping_ups/tests/test_scenario.py
Normal file
18
modules/stock_package_shipping_ups/tests/test_scenario.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
import os
|
||||
|
||||
from trytond.tests.test_tryton import TEST_NETWORK, load_doc_tests
|
||||
|
||||
|
||||
def load_tests(*args, **kwargs):
|
||||
if (not TEST_NETWORK
|
||||
or not (os.getenv('UPS_CLIENT_ID')
|
||||
and os.getenv('UPS_CLIENT_SECRET')
|
||||
and os.getenv('UPS_ACCOUNT_NUMBER'))):
|
||||
kwargs.setdefault('skips', set()).update([
|
||||
'scenario_shipping_ups.rst',
|
||||
'scenario_stock_package_shipping_ups_international.rst',
|
||||
])
|
||||
return load_doc_tests(__name__, __file__, *args, **kwargs)
|
||||
Reference in New Issue
Block a user