first commit

This commit is contained in:
root
2026-03-14 09:42:12 +00:00
commit 0adbd20c2c
10991 changed files with 1646955 additions and 0 deletions

View 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.

View File

@@ -0,0 +1,205 @@
=====================================
Stock Package Shipping MyGLS Scenario
=====================================
Imports::
>>> import os
>>> import uuid
>>> 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 (
... set_fiscalyear_invoice_sequences)
>>> from trytond.modules.company.tests.tools import create_company, get_company
>>> from trytond.tests.tools import activate_modules
Activate modules::
>>> config = activate_modules(
... ['stock_package_shipping_mygls', 'sale', 'sale_shipment_cost'],
... create_company, create_chart)
>>> Address = Model.get('party.address')
>>> Carrier = Model.get('carrier')
>>> CarrierSelection = Model.get('carrier.selection')
>>> Country = Model.get('country.country')
>>> Credential = Model.get('carrier.credential.mygls')
>>> Inventory = Model.get('stock.inventory')
>>> Location = Model.get('stock.location')
>>> Party = Model.get('party.party')
>>> ProductCategory = Model.get('product.category')
>>> ProductTemplate = Model.get('product.template')
>>> ProductUom = Model.get('product.uom')
>>> Sale = Model.get('sale.sale')
Get company::
>>> company = get_company()
Create fiscal year::
>>> fiscalyear = set_fiscalyear_invoice_sequences(create_fiscalyear())
>>> fiscalyear.click('create_period')
Get accounts::
>>> accounts = get_accounts()
Create countries::
>>> hungary = Country(code='HU', name="Hungary")
>>> hungary.save()
Create parties::
>>> customer = Party(name='Customer')
>>> customer.save()
>>> customer_address = customer.addresses.new()
>>> customer_address.street = "Európa u., 2"
>>> customer_address.postal_code = "2351"
>>> customer_address.city = "Alsónémedi"
>>> customer_address.country = hungary
>>> customer_address.save()
>>> customer_phone = customer.contact_mechanisms.new()
>>> customer_phone.type = 'phone'
>>> customer_phone.value = "+36701234567"
>>> customer_phone.save()
Set the warehouse address::
>>> warehouse, = Location.find([('type', '=', 'warehouse')])
>>> company_address = Address()
>>> company_address.party = company.party
>>> company_address.street = "Európa u., 2"
>>> company_address.postal_code = "2351"
>>> company_address.city = "Alsónémedi"
>>> company_address.country = hungary
>>> company_address.save()
>>> company_phone = company.party.contact_mechanisms.new()
>>> company_phone.type = 'phone'
>>> company_phone.value = "+36701234567"
>>> company_phone.save()
>>> warehouse.address = company_address
>>> warehouse.save()
Create account category::
>>> account_category = ProductCategory(name="Account Category")
>>> account_category.accounting = True
>>> account_category.account_expense = accounts['expense']
>>> account_category.account_revenue = accounts['revenue']
>>> account_category.save()
Create product::
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
>>> template = ProductTemplate()
>>> template.name = 'product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.salable = True
>>> template.list_price = Decimal('10')
>>> template.account_category = account_category
>>> template.save()
>>> product, = template.products
Create an 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')
>>> box = PackageType(name='Box')
>>> box.save()
Create a MyGLS carrier::
>>> credential = Credential()
>>> credential.company = company
>>> credential.server = 'testing'
>>> credential.country = 'hu'
>>> credential.username = os.getenv('MYGLS_USERNAME')
>>> credential.password = os.getenv('MYGLS_PASSWORD')
>>> credential.client_number = int(os.getenv('MYGLS_CLIENT_NUMBER'))
>>> credential.save()
>>> template = ProductTemplate()
>>> template.name = "GLS"
>>> template.default_uom = unit
>>> template.type = 'service'
>>> template.salable = True
>>> template.list_price = Decimal(20)
>>> template.account_category = account_category
>>> template.save()
>>> carrier_product, = template.products
>>> gls = Party(name="GLS")
>>> gls.save()
>>> carrier = Carrier()
>>> carrier.party = gls
>>> carrier.carrier_product = carrier_product
>>> carrier.shipping_service = 'mygls'
>>> carrier.mygls_type_of_printer = 'A4_2x2'
>>> carrier.mygls_print_position = 3
>>> carrier.mygls_services = ['CS1', 'TGS']
>>> carrier.save()
Create a sale and thus a shipment::
>>> sale = Sale()
>>> sale.party = customer
>>> sale.shipment_address = customer_address
>>> sale.invoice_method = 'order'
>>> sale.carrier = carrier
>>> sale_line = sale.lines.new()
>>> sale_line.product = product
>>> sale_line.quantity = 1.0
>>> sale_line = sale.lines.new()
>>> sale_line.product = product
>>> sale_line.quantity = 1.0
>>> sale.click('quote')
>>> sale.click('confirm')
>>> sale.click('process')
Create the packages and ship the shipment::
>>> shipment, = sale.shipments
>>> shipment.click('assign_force')
>>> shipment.click('pick')
>>> shipment.shipping_description = str(uuid.uuid4())
>>> pack = shipment.packages.new(type=box)
>>> pack_moves = pack.moves.find([])
>>> pack.moves.append(pack_moves[0])
>>> pack = shipment.packages.new(type=box)
>>> pack.moves.append(pack_moves[1])
>>> 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
'application/pdf'
>>> pack.mygls_shipping_id is not None
True
>>> bool(pack.shipping_reference)
True

View File

@@ -0,0 +1,12 @@
# 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 StockPackageShippingMyglsTestCase(ModuleTestCase):
'Test Stock Package Shipping Mygls module'
module = 'stock_package_shipping_mygls'
del ModuleTestCase

View File

@@ -0,0 +1,16 @@
# 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('MYGLS_USERNAME')
and os.getenv('MYGLS_PASSWORD')
and os.getenv('MYGLS_CLIENT_NUMBER'))):
kwargs.setdefault('skips', set()).add(
'scenario_stock_package_shipping_mygls.rst')
return load_doc_tests(__name__, __file__, *args, **kwargs)