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,209 @@
====================
Sale Supply Scenario
====================
Imports::
>>> from decimal import Decimal
>>> from proteus import Model, Wizard
>>> 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
>>> from trytond.tests.tools import activate_modules
Activate modules::
>>> config = activate_modules(
... ['sale_supply', 'sale', 'purchase'],
... create_company, create_chart)
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 parties::
>>> Party = Model.get('party.party')
>>> supplier = Party(name='Supplier')
>>> supplier.save()
>>> 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_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.purchasable = True
>>> template.salable = True
>>> template.list_price = Decimal('10')
>>> template.supply_on_sale = 'always'
>>> template.account_category = account_category
>>> template.save()
>>> product, = template.products
Create payment term::
>>> payment_term = create_payment_term()
>>> payment_term.save()
Sale 250 products::
>>> Sale = Model.get('sale.sale')
>>> sale = Sale()
>>> sale.party = customer
>>> sale.payment_term = payment_term
>>> sale_line = sale.lines.new()
>>> sale_line.product = product
>>> sale_line.quantity = 250
>>> sale.click('quote')
>>> sale.click('confirm')
>>> sale.state
'processing'
>>> shipment, = sale.shipments
>>> move, = shipment.outgoing_moves
>>> move.state
'staging'
>>> move, = shipment.inventory_moves
>>> move.state
'staging'
Delete Purchase Request::
>>> PurchaseRequest = Model.get('purchase.request')
>>> purchase_request, = PurchaseRequest.find()
>>> purchase_request.quantity
250.0
>>> purchase_request.delete()
>>> purchase_request, = PurchaseRequest.find()
>>> purchase_request.quantity
250.0
Create Purchase from Request::
>>> Purchase = Model.get('purchase.purchase')
>>> purchase_request, = PurchaseRequest.find()
>>> purchase_request.quantity
250.0
>>> create_purchase = Wizard('purchase.request.create_purchase',
... [purchase_request])
>>> create_purchase.form.party = supplier
>>> create_purchase.execute('start')
>>> purchase, = Purchase.find()
>>> purchase.payment_term = payment_term
>>> purchase_line, = purchase.lines
>>> purchase_line.unit_price = Decimal('5.0000')
>>> purchase.click('quote')
>>> purchase.click('confirm')
>>> purchase.state
'processing'
>>> sale.reload()
>>> shipment, = sale.shipments
>>> move, = shipment.outgoing_moves
>>> move.state
'draft'
>>> move, = shipment.inventory_moves
>>> move.state
'draft'
Receive 100 products::
>>> ShipmentIn = Model.get('stock.shipment.in')
>>> Move = Model.get('stock.move')
>>> shipment = ShipmentIn(supplier=supplier)
>>> move, = shipment.incoming_moves.find()
>>> shipment.incoming_moves.append(move)
>>> move.quantity = 100
>>> shipment.click('receive')
>>> shipment.click('do')
>>> shipment.state
'done'
>>> sale.reload()
>>> shipment, = sale.shipments
>>> move, = [x for x in shipment.inventory_moves
... if x.state == 'assigned']
>>> move.quantity
100.0
>>> move, = [x for x in shipment.inventory_moves
... if x.state == 'draft']
>>> move.quantity
150.0
Switching from not supplying on sale to supplying on sale for product should
not create a new purchase request::
>>> changing_template = ProductTemplate()
>>> changing_template.name = 'product'
>>> changing_template.default_uom = unit
>>> changing_template.type = 'goods'
>>> changing_template.purchasable = True
>>> changing_template.salable = True
>>> changing_template.list_price = Decimal('10')
>>> changing_template.account_category = account_category
>>> changing_template.supply_on_sale = None
>>> changing_template.save()
>>> changing_product, = changing_template.products
>>> Sale = Model.get('sale.sale')
>>> sale = Sale()
>>> sale.party = customer
>>> sale.payment_term = payment_term
>>> sale_line = sale.lines.new()
>>> sale_line.product = changing_product
>>> sale_line.quantity = 100
>>> sale.click('quote')
>>> sale.click('confirm')
>>> sale.state
'processing'
>>> shipment, = sale.shipments
>>> Inventory = Model.get('stock.inventory')
>>> Location = Model.get('stock.location')
>>> storage, = Location.find([
... ('code', '=', 'STO'),
... ])
>>> inventory = Inventory()
>>> inventory.location = storage
>>> inventory.save()
>>> inventory_line = inventory.lines.new()
>>> inventory_line.product = changing_product
>>> inventory_line.quantity = 100.0
>>> inventory_line.expected_quantity = 0.0
>>> inventory.save()
>>> inventory.click('confirm')
>>> inventory.state
'done'
>>> shipment.click('assign_try')
>>> shipment.click('pick')
>>> shipment.click('pack')
>>> changing_template.supply_on_sale = 'always'
>>> changing_template.save()
>>> shipment.click('do')
>>> len(PurchaseRequest.find([('product', '=', changing_product.id)]))
0

View File

@@ -0,0 +1,53 @@
=========================
Sale Supply Notifications
=========================
Imports::
>>> from proteus import Model
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules
Activate modules::
>>> config = activate_modules(['sale_supply', 'stock_supply'], create_company)
>>> Location = Model.get('stock.location')
>>> OrderPoint = Model.get('stock.order_point')
>>> ProductTemplate = Model.get('product.template')
>>> UoM = Model.get('product.uom')
Get locations::
>>> warehouse_location, = Location.find([('type', '=', 'warehouse')])
Create product::
>>> unit, = UoM.find([('name', '=', "Unit")])
>>> product_template = ProductTemplate()
>>> product_template.name = "Product"
>>> product_template.type = 'goods'
>>> product_template.default_uom = unit
>>> product_template.purchasable = True
>>> product_template.salable = True
>>> product_template.supply_on_sale = 'always'
>>> product_template.save()
>>> product, = product_template.products
Create order point::
>>> order_point = OrderPoint()
>>> order_point.product = product
>>> order_point.location = warehouse_location
>>> order_point.type = 'purchase'
>>> order_point.min_quantity = 0
>>> order_point.target_quantity = 5
>>> order_point.save()
Check notifications::
>>> len(product_template.notifications())
1
>>> len(order_point.notifications())
1

View File

@@ -0,0 +1,150 @@
======================================
Sale Supply Request Cancelled Scenario
======================================
Imports::
>>> from decimal import Decimal
>>> from proteus import Model, Wizard
>>> from trytond.modules.account.tests.tools import create_chart, get_accounts
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules
Activate modules::
>>> config = activate_modules('sale_supply', create_company, create_chart)
>>> Party = Model.get('party.party')
>>> ProductCategory = Model.get('product.category')
>>> ProductTemplate = Model.get('product.template')
>>> Purchase = Model.get('purchase.purchase')
>>> PurchaseRequest = Model.get('purchase.request')
>>> Sale = Model.get('sale.sale')
>>> UoM = Model.get('product.uom')
Get accounts::
>>> accounts = get_accounts()
Create parties::
>>> supplier = Party(name="Supplier")
>>> supplier.save()
>>> customer = Party(name="Customer")
>>> customer.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, = UoM.find([('name', '=', "Unit")])
>>> template = ProductTemplate(name="Product")
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.purchasable = True
>>> template.salable = True
>>> template.list_price = Decimal('100.0000')
>>> template.supply_on_sale = 'always'
>>> product_supplier = template.product_suppliers.new()
>>> product_supplier.party = supplier
>>> template.account_category = account_category
>>> template.save()
>>> product, = template.products
Sale product::
>>> sale = Sale(party=customer)
>>> line = sale.lines.new()
>>> line.product = product
>>> line.quantity = 1
>>> sale.click('quote')
>>> sale.click('confirm')
>>> sale.state
'processing'
>>> shipment, = sale.shipments
>>> shipment.state
'waiting'
>>> [m.state for m in shipment.moves]
['staging', 'staging']
Create purchase from request::
>>> purchase_request, = PurchaseRequest.find()
>>> create_purchase = Wizard(
... 'purchase.request.create_purchase', [purchase_request])
>>> purchase_request.state
'purchased'
>>> shipment.reload()
>>> [m.state for m in shipment.moves]
['staging', 'staging']
Cancel purchase::
>>> purchase = purchase_request.purchase
>>> purchase.click('cancel')
>>> purchase.state
'cancelled'
>>> purchase_request.reload()
>>> purchase_request.state
'exception'
>>> shipment.reload()
>>> [m.state for m in shipment.moves]
['staging', 'staging']
Reset exception::
>>> handle_purchase = purchase_request.click(
... 'handle_purchase_cancellation_exception')
>>> handle_purchase.execute('reset')
>>> purchase_request.state
'draft'
>>> shipment.reload()
>>> [m.state for m in shipment.moves]
['staging', 'staging']
Cancel again purchase::
>>> create_purchase = Wizard(
... 'purchase.request.create_purchase', [purchase_request])
>>> purchase = purchase_request.purchase
>>> purchase.click('cancel')
>>> purchase.state
'cancelled'
>>> purchase_request.reload()
>>> purchase_request.state
'exception'
>>> shipment.reload()
>>> [m.state for m in shipment.moves]
['staging', 'staging']
Cancel request::
>>> handle_purchase = purchase_request.click(
... 'handle_purchase_cancellation_exception')
>>> handle_purchase.execute('cancel_request')
>>> purchase_request.state
'cancelled'
>>> shipment.reload()
>>> move, = shipment.moves
>>> move.state
'cancelled'
>>> shipment.state
'cancelled'
>>> sale.reload()
>>> sale.shipment_state
'exception'

View File

@@ -0,0 +1,123 @@
=============================================
Sale Supply with Shipment on Invoice 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 (
... set_fiscalyear_invoice_sequences)
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules
Activate modules::
>>> config = activate_modules('sale_supply', create_company, create_chart)
Create fiscal year::
>>> fiscalyear = set_fiscalyear_invoice_sequences(create_fiscalyear())
>>> fiscalyear.click('create_period')
Get accounts::
>>> accounts = get_accounts()
>>> Journal = Model.get('account.journal')
>>> PaymentMethod = Model.get('account.invoice.payment.method')
>>> cash_journal, = Journal.find([('type', '=', 'cash')])
>>> cash_journal.save()
>>> payment_method = PaymentMethod()
>>> payment_method.name = 'Cash'
>>> payment_method.journal = cash_journal
>>> payment_method.credit_account = accounts['cash']
>>> payment_method.debit_account = accounts['cash']
>>> payment_method.save()
Create parties::
>>> 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_expense = accounts['expense']
>>> account_category.account_revenue = accounts['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.purchasable = True
>>> template.list_price = Decimal('10')
>>> template.supply_on_sale = 'always'
>>> template.account_category = account_category
>>> template.save()
>>> product, = template.products
Sale 5 products with shipment method on invoice::
>>> Sale = Model.get('sale.sale')
>>> sale = Sale()
>>> sale.party = customer
>>> sale.shipment_method = 'invoice'
>>> sale_line = sale.lines.new()
>>> sale_line.product = product
>>> sale_line.quantity = 5
>>> sale.click('quote')
>>> sale.click('confirm')
>>> sale.click('process')
>>> sale.state
'processing'
>>> len(sale.shipments)
0
>>> invoice, = sale.invoices
>>> sale_line, = sale.lines
>>> sale_line.purchase_request
Pay for 4 products::
>>> invoice_line, = invoice.lines
>>> invoice_line.quantity = 4
>>> invoice.click('post')
>>> pay = invoice.click('pay')
>>> pay.form.payment_method = payment_method
>>> pay.execute('choice')
Not yet a purchase request::
>>> sale_line.reload()
>>> sale_line.purchase_request
Pay for remaining products::
>>> sale.reload()
>>> _, invoice = sale.invoices
>>> invoice.click('post')
>>> pay = invoice.click('pay')
>>> pay.form.payment_method = payment_method
>>> pay.execute('choice')
Check purchase request::
>>> sale_line.reload()
>>> bool(sale_line.purchase_request)
True
>>> sale_line.purchase_request.quantity
5.0

View File

@@ -0,0 +1,123 @@
================================
Sale Supply Stock First Scenario
================================
Imports::
>>> from decimal import Decimal
>>> from proteus import Model
>>> from trytond.modules.account.tests.tools import create_chart, get_accounts
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules
Activate modules::
>>> config = activate_modules('sale_supply', create_company, create_chart)
>>> 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')
>>> Sale = Model.get('sale.sale')
>>> UoM = Model.get('product.uom')
Get accounts::
>>> accounts = get_accounts()
Create parties::
>>> supplier = Party(name="Supplier")
>>> supplier.save()
>>> customer = Party(name="Customer")
>>> customer.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, = UoM.find([('name', '=', "Unit")])
>>> template = ProductTemplate(name="Product")
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.purchasable = True
>>> template.salable = True
>>> template.list_price = Decimal('100.0000')
>>> template.supply_on_sale = 'stock_first'
>>> template.account_category = account_category
>>> template.save()
>>> product, = template.products
Fill warehouse::
>>> inventory = Inventory()
>>> inventory.location, = Location.find([('code', '=', 'STO')])
>>> line = inventory.lines.new()
>>> line.product = product
>>> line.quantity = 5
>>> inventory.click('confirm')
>>> inventory.state
'done'
Sale 3 products with 5 in stock::
>>> sale = Sale()
>>> sale.party = customer
>>> line = sale.lines.new()
>>> line.product = product
>>> line.quantity = 3
>>> sale.click('quote')
>>> sale.click('confirm')
>>> sale.state
'processing'
>>> line, = sale.lines
>>> bool(line.purchase_request)
False
>>> move, = line.moves
>>> move.state
'draft'
Sale 3 products with 2 in stock::
>>> sale = Sale()
>>> sale.party = customer
>>> line = sale.lines.new()
>>> line.product = product
>>> line.quantity = 3
>>> sale.click('quote')
>>> sale.click('confirm')
>>> sale.state
'processing'
>>> line, = sale.lines
>>> bool(line.purchase_request)
False
>>> move, = line.moves
>>> move.state
'draft'
Sale 4 products with no stock::
>>> sale = Sale()
>>> sale.party = customer
>>> line = sale.lines.new()
>>> line.product = product
>>> line.quantity = 4
>>> sale.click('quote')
>>> sale.click('confirm')
>>> sale.state
'processing'
>>> line, = sale.lines
>>> bool(line.purchase_request)
True
>>> move, = line.moves
>>> move.state
'staging'

View 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 SaleSupplyTestCase(ModuleTestCase):
'Test SaleSupply module'
module = 'sale_supply'
extras = ['stock_supply']
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)