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,252 @@
=======================
Carrier Weight Scenario
=======================
Imports::
>>> 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([
... 'carrier_weight',
... 'purchase_shipment_cost',
... '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']
Create supplier::
>>> Party = Model.get('party.party')
>>> supplier = Party(name='Supplier')
>>> supplier.save()
Create customer::
>>> Party = Model.get('party.party')
>>> customer = Party(name='Customer')
>>> customer.save()
Create account category::
>>> ProductCategory = Model.get('product.category')
>>> account_category = ProductCategory(name="Account Category")
>>> account_category.accounting = True
>>> account_category.account_revenue = revenue
>>> account_category.save()
Create product::
>>> ProductUom = Model.get('product.uom')
>>> ProductTemplate = Model.get('product.template')
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
>>> gram, = ProductUom.find([('name', '=', 'Gram')])
>>> template = ProductTemplate()
>>> template.name = 'Product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.salable = True
>>> template.list_price = Decimal('20')
>>> template.account_category = account_category
>>> template.weight = 250
>>> template.weight_uom = gram
>>> template.save()
>>> product, = template.products
>>> product.cost_price = Decimal('8')
>>> product.save()
>>> carrier_template = ProductTemplate()
>>> carrier_template.name = 'Carrier Product'
>>> carrier_template.default_uom = unit
>>> carrier_template.type = 'service'
>>> carrier_template.salable = True
>>> carrier_template.list_price = Decimal('3')
>>> carrier_template.account_category = account_category
>>> carrier_template.save()
>>> carrier_product, = carrier_template.products
>>> carrier_product.cost_price = Decimal('3')
>>> carrier_product.save()
Create carrier::
>>> Carrier = Model.get('carrier')
>>> kilogram, = ProductUom.find([('name', '=', 'Kilogram')])
>>> carrier = Carrier()
>>> party = Party(name='Carrier')
>>> party.save()
>>> carrier.party = party
>>> carrier.carrier_product = carrier_product
>>> carrier.carrier_cost_method = 'weight'
>>> carrier.weight_currency = company.currency
>>> carrier.weight_uom = kilogram
>>> for weight, price in (
... (0.5, Decimal(25)),
... (1, Decimal(40)),
... (5, Decimal(180)),
... ):
... line = carrier.weight_price_list.new(weight=weight, price=price)
>>> carrier.save()
Receive a single product line::
>>> ShipmentIn = Model.get('stock.shipment.in')
>>> Location = Model.get('stock.location')
>>> supplier_location, = Location.find([
... ('code', '=', 'SUP'),
... ])
>>> shipment = ShipmentIn()
>>> shipment.supplier = supplier
>>> move = shipment.incoming_moves.new()
>>> move.from_location = supplier_location
>>> move.to_location = shipment.warehouse.input_location
>>> move.product = product
>>> move.quantity = 4
>>> move.unit_price = Decimal('8')
>>> move.currency = company.currency
>>> shipment.carrier = carrier
>>> shipment.cost_used
Decimal('25.0000')
>>> assertEqual(shipment.cost_currency_used, company.currency)
>>> shipment.click('receive')
>>> shipment.state
'received'
>>> move, = shipment.incoming_moves
>>> move.unit_price
Decimal('14.2500')
Create payment term::
>>> payment_term = create_payment_term()
>>> payment_term.save()
Sale products with cost on shipment::
>>> Sale = Model.get('sale.sale')
>>> sale = Sale()
>>> sale.party = customer
>>> sale.carrier = carrier
>>> sale.payment_term = payment_term
>>> sale.invoice_method = 'shipment'
>>> sale.shipment_cost_method = 'shipment'
>>> sale_line = sale.lines.new()
>>> sale_line.product = product
>>> sale_line.quantity = 3.0
>>> sale_line = sale.lines.new()
>>> sale_line.product = product
>>> sale_line.quantity = 2.0
>>> sale_line = sale.lines.new()
>>> sale_line.type = 'comment'
>>> sale_line.description = 'Comment'
>>> sale.click('quote')
>>> cost_line = sale.lines[-1]
>>> assertEqual(cost_line.product, carrier_product)
>>> cost_line.quantity
1.0
>>> cost_line.amount
Decimal('40.00')
>>> sale.click('confirm')
>>> sale.click('process')
>>> sale.state
'processing'
>>> sale.untaxed_amount
Decimal('140.00')
Send products::
>>> ShipmentOut = Model.get('stock.shipment.out')
>>> shipment, = sale.shipments
>>> assertEqual(shipment.carrier, carrier)
>>> shipment.cost_used
Decimal('40.0000')
>>> shipment.cost_sale_used
Decimal('40.0000')
>>> assertEqual(shipment.cost_sale_currency_used, company.currency)
>>> move = shipment.inventory_moves[0]
>>> move.quantity -= 1
>>> shipment.cost_used
Decimal('25.0000')
>>> shipment.cost_sale_used
Decimal('25.0000')
>>> assertEqual(shipment.cost_sale_currency_used, company.currency)
>>> shipment.state
'waiting'
>>> shipment.click('assign_force')
>>> shipment.state
'assigned'
>>> shipment.click('pick')
>>> shipment.state
'picked'
>>> shipment.click('pack')
>>> shipment.state
'packed'
>>> shipment.click('do')
>>> shipment.state
'done'
Check customer invoice::
>>> sale.reload()
>>> invoice, = sale.invoices
>>> invoice.untaxed_amount
Decimal('105.00')
Sale products with cost on order::
>>> sale = Sale()
>>> sale.party = customer
>>> sale.carrier = carrier
>>> sale.payment_term = payment_term
>>> sale.invoice_method = 'order'
>>> sale.shipment_cost_method = 'order'
>>> sale_line = sale.lines.new()
>>> sale_line.product = product
>>> sale_line.quantity = 3.0
>>> sale.click('quote')
>>> cost_line = sale.lines[-1]
>>> assertEqual(cost_line.product, carrier_product)
>>> cost_line.quantity
1.0
>>> cost_line.amount
Decimal('25.00')
>>> sale.click('confirm')
>>> sale.click('process')
>>> sale.state
'processing'
>>> sale.untaxed_amount
Decimal('85.00')
Check customer shipment::
>>> shipment, = sale.shipments
>>> assertEqual(shipment.carrier, carrier)
Check customer invoice::
>>> sale.reload()
>>> invoice, = sale.invoices
>>> invoice.untaxed_amount
Decimal('85.00')

View File

@@ -0,0 +1,104 @@
# 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.modules.company.tests import CompanyTestMixin
from trytond.modules.currency.tests import create_currency
from trytond.pool import Pool
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
from trytond.transaction import Transaction
class CarrierWeightTestCase(CompanyTestMixin, ModuleTestCase):
'Test CarrierWeight module'
module = 'carrier_weight'
extras = [
'purchase_shipment_cost', 'sale_shipment_cost', 'stock_shipment_cost']
def create_carrier(self):
pool = Pool()
Party = pool.get('party.party')
Uom = pool.get('product.uom')
Template = pool.get('product.template')
Product = pool.get('product.product')
Carrier = pool.get('carrier')
WeightPriceList = pool.get('carrier.weight_price_list')
party, = Party.create([{
'name': 'Carrier',
}])
uom, = Uom.search([
('name', '=', 'Unit'),
])
template, = Template.create([{
'name': 'Carrier',
'default_uom': uom.id,
'type': 'service',
}])
product, = Product.create([{
'template': template.id,
}])
weight_uom, = Uom.search([
('name', '=', 'Kilogram'),
])
currency = create_currency('cu1')
carrier, = Carrier.create([{
'party': party.id,
'carrier_product': product.id,
'carrier_cost_method': 'weight',
'weight_uom': weight_uom.id,
'weight_currency': currency.id,
}])
for i, weight in enumerate(range(0, 100, 20), 1):
WeightPriceList.create([{
'carrier': carrier.id,
'weight': weight,
'price': Decimal(i),
}])
return carrier
@with_transaction()
def test_compute_weight_price(self):
'Test compute_weight_price'
carrier = self.create_carrier()
for weight, price in [
(-1, Decimal(0)),
(0, Decimal(1)),
(1, Decimal(1)),
(10, Decimal(1)),
(20, Decimal(1)),
(21, Decimal(2)),
(80, Decimal(4)),
(81, Decimal(5)),
(100, Decimal(5)),
]:
with self.subTest(weight=weight):
self.assertEqual(carrier.compute_weight_price(weight), price)
@with_transaction()
def test_get_weight_price(self):
"Test get_weight_price"
transaction = Transaction()
carrier = self.create_carrier()
for weights, price in [
([], Decimal(1)),
([0], Decimal(1)),
([0, 0], Decimal(2)),
([21], Decimal(2)),
([10, 21], Decimal(3)),
([0, 21], Decimal(3)),
]:
with self.subTest(weights=weights):
with transaction.set_context(weights=weights):
self.assertEqual(
carrier.get_sale_price(),
(price, carrier.weight_currency.id))
self.assertEqual(
carrier.get_purchase_price(),
(price, carrier.weight_currency.id))
del ModuleTestCase

View File

@@ -0,0 +1,8 @@
# 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 load_doc_tests
def load_tests(*args, **kwargs):
return load_doc_tests(__name__, __file__, *args, **kwargs)