first commit
This commit is contained in:
2
modules/purchase_request/tests/__init__.py
Normal file
2
modules/purchase_request/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.
221
modules/purchase_request/tests/scenario_purchase_request.rst
Normal file
221
modules/purchase_request/tests/scenario_purchase_request.rst
Normal file
@@ -0,0 +1,221 @@
|
||||
=========================
|
||||
Purchase Request Scenario
|
||||
=========================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> 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, assertEqual, set_user
|
||||
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... ['purchase_request', 'stock_supply'],
|
||||
... create_company, create_chart)
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> expense = accounts['expense']
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.save()
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.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.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'Product'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.list_price = Decimal('20')
|
||||
>>> template.purchasable = True
|
||||
>>> template.account_category = account_category
|
||||
>>> product, = template.products
|
||||
>>> product.cost_price = Decimal('8')
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Get stock locations::
|
||||
|
||||
>>> Location = Model.get('stock.location')
|
||||
>>> warehouse_loc, = Location.find([('code', '=', 'WH')])
|
||||
>>> supplier_loc, = Location.find([('code', '=', 'SUP')])
|
||||
>>> customer_loc, = Location.find([('code', '=', 'CUS')])
|
||||
>>> output_loc, = Location.find([('code', '=', 'OUT')])
|
||||
>>> storage_loc, = Location.find([('code', '=', 'STO')])
|
||||
|
||||
Create a need for missing product::
|
||||
|
||||
>>> ShipmentOut = Model.get('stock.shipment.out')
|
||||
>>> shipment_out = ShipmentOut()
|
||||
>>> shipment_out.planned_date = today
|
||||
>>> shipment_out.effective_date = today
|
||||
>>> shipment_out.customer = customer
|
||||
>>> shipment_out.warehouse = warehouse_loc
|
||||
>>> move = shipment_out.outgoing_moves.new()
|
||||
>>> move.product = product
|
||||
>>> move.unit = unit
|
||||
>>> move.quantity = 1
|
||||
>>> move.from_location = output_loc
|
||||
>>> move.to_location = customer_loc
|
||||
>>> move.company = shipment_out.company
|
||||
>>> move.unit_price = Decimal('1')
|
||||
>>> move.currency = shipment_out.company.currency
|
||||
>>> shipment_out.click('wait')
|
||||
|
||||
There is no purchase request::
|
||||
|
||||
>>> PurchaseRequest = Model.get('purchase.request')
|
||||
>>> PurchaseRequest.find([])
|
||||
[]
|
||||
|
||||
Create the purchase request::
|
||||
|
||||
>>> create_pr = Wizard('stock.supply')
|
||||
>>> create_pr.execute('create_')
|
||||
|
||||
There is now a draft purchase request::
|
||||
|
||||
>>> pr, = PurchaseRequest.find([('state', '=', 'draft')])
|
||||
>>> assertEqual(pr.product, product)
|
||||
>>> pr.quantity
|
||||
1.0
|
||||
|
||||
Create the purchase then cancel it::
|
||||
|
||||
>>> create_purchase = pr.click('create_purchase')
|
||||
>>> create_purchase.form.party = supplier
|
||||
>>> create_purchase.execute('start')
|
||||
>>> pr.state
|
||||
'purchased'
|
||||
>>> (purchase,), = create_purchase.actions
|
||||
>>> purchase.click('cancel')
|
||||
>>> pr.reload()
|
||||
>>> pr.state
|
||||
'exception'
|
||||
|
||||
Handle the exception::
|
||||
|
||||
>>> handle_exception = pr.click('handle_purchase_cancellation_exception')
|
||||
>>> handle_exception.execute('reset')
|
||||
>>> pr.state
|
||||
'draft'
|
||||
|
||||
Recreate a purchase and cancel it again::
|
||||
|
||||
>>> create_purchase = pr.click('create_purchase')
|
||||
>>> pr.state
|
||||
'purchased'
|
||||
>>> (purchase,), = create_purchase.actions
|
||||
>>> purchase.click('cancel')
|
||||
>>> pr.reload()
|
||||
>>> pr.state
|
||||
'exception'
|
||||
|
||||
Handle again the exception::
|
||||
|
||||
>>> handle_exception = pr.click('handle_purchase_cancellation_exception')
|
||||
>>> handle_exception.execute('cancel_request')
|
||||
>>> pr.state
|
||||
'cancelled'
|
||||
|
||||
Re-create the purchase request::
|
||||
|
||||
>>> create_pr = Wizard('stock.supply')
|
||||
>>> create_pr.execute('create_')
|
||||
|
||||
Create a second purchase request manually::
|
||||
|
||||
>>> ctx = config.context
|
||||
>>> set_user(0) # root
|
||||
>>> pr_id, = PurchaseRequest.create([{
|
||||
... 'product': product.id,
|
||||
... 'quantity': 1,
|
||||
... 'unit': unit,
|
||||
... 'warehouse': warehouse_loc.id,
|
||||
... 'origin': 'stock.order_point,-1',
|
||||
... }], ctx)
|
||||
>>> set_user()
|
||||
>>> pr = PurchaseRequest(pr_id)
|
||||
|
||||
There is now 2 draft purchase requests::
|
||||
|
||||
>>> prs = PurchaseRequest.find([('state', '=', 'draft')])
|
||||
>>> len(prs)
|
||||
2
|
||||
|
||||
Create the purchase with a unique line::
|
||||
|
||||
>>> create_purchase = PurchaseRequest.click(prs, 'create_purchase')
|
||||
>>> create_purchase.form.party = supplier
|
||||
>>> create_purchase.execute('start')
|
||||
>>> pr.state
|
||||
'purchased'
|
||||
>>> (purchase,), = create_purchase.actions
|
||||
>>> len(purchase.lines)
|
||||
1
|
||||
>>> line, = purchase.lines
|
||||
>>> assertEqual(line.product, product)
|
||||
>>> line.quantity
|
||||
2.0
|
||||
>>> assertEqual(line.unit, unit)
|
||||
|
||||
Create a purchase request without product::
|
||||
|
||||
>>> ctx = config.context
|
||||
>>> set_user(0) # root
|
||||
>>> pr_id, = PurchaseRequest.create([{
|
||||
... 'description': "Custom product",
|
||||
... 'quantity': 1,
|
||||
... 'origin': 'stock.order_point,-1',
|
||||
... }], ctx)
|
||||
>>> set_user()
|
||||
>>> pr = PurchaseRequest(pr_id)
|
||||
>>> pr.save()
|
||||
|
||||
Create the purchase without product::
|
||||
|
||||
>>> create_purchase = pr.click('create_purchase')
|
||||
>>> create_purchase.form.party = supplier
|
||||
>>> create_purchase.execute('start')
|
||||
>>> pr.state
|
||||
'purchased'
|
||||
|
||||
>>> pr.purchase_line.product
|
||||
>>> pr.purchase_line.description
|
||||
'Custom product'
|
||||
>>> pr.purchase_line.quantity
|
||||
1.0
|
||||
>>> pr.purchase_line.unit
|
||||
>>> pr.purchase_line.unit_price
|
||||
|
||||
It's not possible to delete a purchase linked to a purchase_request::
|
||||
|
||||
>>> pr.purchase_line.purchase.delete()
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
AccessError: ...
|
||||
74
modules/purchase_request/tests/test_module.py
Normal file
74
modules/purchase_request/tests/test_module.py
Normal file
@@ -0,0 +1,74 @@
|
||||
# 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 datetime as dt
|
||||
|
||||
from trytond.modules.company.tests import create_company, set_company
|
||||
from trytond.modules.party.tests import PartyCheckReplaceMixin
|
||||
from trytond.pool import Pool
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
|
||||
|
||||
class PurchaseRequestTestCase(PartyCheckReplaceMixin, ModuleTestCase):
|
||||
'Test Purchase Request module'
|
||||
module = 'purchase_request'
|
||||
|
||||
@with_transaction()
|
||||
def test_find_best_product_supplier(self):
|
||||
"Test finding best product supplier"
|
||||
pool = Pool()
|
||||
ProductTemplate = pool.get('product.template')
|
||||
Product = pool.get('product.product')
|
||||
ProductSupplier = pool.get('purchase.product_supplier')
|
||||
Party = pool.get('party.party')
|
||||
UoM = pool.get('product.uom')
|
||||
PurchaseRequest = pool.get('purchase.request')
|
||||
Date = pool.get('ir.date')
|
||||
|
||||
supplier = Party(name="Supplier")
|
||||
supplier.save()
|
||||
|
||||
company = create_company()
|
||||
with set_company(company):
|
||||
unit, = UoM.search([('name', '=', "Unit")])
|
||||
template = ProductTemplate(name="Product")
|
||||
template.purchasable = True
|
||||
template.default_uom = unit
|
||||
template.purchase_uom = unit
|
||||
template.save()
|
||||
product = Product(template=template)
|
||||
product.save()
|
||||
|
||||
product_supplier1 = ProductSupplier(
|
||||
template=template, party=supplier,
|
||||
lead_time=dt.timedelta(days=5))
|
||||
product_supplier1.save()
|
||||
product_supplier2 = ProductSupplier(
|
||||
template=template, party=supplier,
|
||||
lead_time=dt.timedelta(days=2))
|
||||
product_supplier2.save()
|
||||
product_supplier3 = ProductSupplier(
|
||||
template=template, party=supplier,
|
||||
lead_time=dt.timedelta(days=3))
|
||||
product_supplier3.save()
|
||||
|
||||
today = Date.today()
|
||||
for date, product_supplier in [
|
||||
(None, product_supplier1),
|
||||
(today, product_supplier2),
|
||||
(today + dt.timedelta(days=1), product_supplier2),
|
||||
(today + dt.timedelta(days=2), product_supplier2),
|
||||
(today + dt.timedelta(days=3), product_supplier2),
|
||||
(today + dt.timedelta(days=4), product_supplier2),
|
||||
(today + dt.timedelta(days=5), product_supplier1),
|
||||
(dt.date.max, product_supplier1),
|
||||
(dt.date.min, product_supplier2),
|
||||
]:
|
||||
with self.subTest(date=date):
|
||||
self.assertEqual(
|
||||
PurchaseRequest.find_best_product_supplier(
|
||||
product, date),
|
||||
product_supplier)
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/purchase_request/tests/test_scenario.py
Normal file
8
modules/purchase_request/tests/test_scenario.py
Normal 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)
|
||||
Reference in New Issue
Block a user