first commit
This commit is contained in:
2
modules/purchase_product_quantity/tests/__init__.py
Normal file
2
modules/purchase_product_quantity/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,119 @@
|
||||
==================================
|
||||
Purchase Product Quantity 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, assertEqual, set_user
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... ['purchase_product_quantity', 'purchase_request'],
|
||||
... create_company, create_chart)
|
||||
|
||||
>>> 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')
|
||||
>>> PurchaseRequest = Model.get('purchase.request')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> supplier = Party(name="Supplier")
|
||||
>>> supplier.save()
|
||||
|
||||
Create account category::
|
||||
|
||||
>>> account_category = ProductCategory(name="Account Category")
|
||||
>>> account_category.accounting = True
|
||||
>>> account_category.account_expense = accounts['expense']
|
||||
>>> account_category.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> gr, = ProductUom.find([('name', '=', "Gram")])
|
||||
>>> kg, = ProductUom.find([('name', '=', "Kilogram")])
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'Product'
|
||||
>>> template.default_uom = gr
|
||||
>>> template.type = 'goods'
|
||||
>>> template.list_price = Decimal('20')
|
||||
>>> template.account_category = account_category
|
||||
>>> template.purchasable = True
|
||||
>>> template.purchase_uom = kg
|
||||
>>> product_supplier = template.product_suppliers.new()
|
||||
>>> product_supplier.party = supplier
|
||||
>>> product_supplier.quantity_minimal = 0.1
|
||||
>>> product_supplier.quantity_rounding = 0.05
|
||||
>>> product, = template.products
|
||||
>>> product.cost_price = Decimal('8')
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Get stock locations::
|
||||
|
||||
>>> warehouse_loc, = Location.find([('code', '=', 'WH')])
|
||||
|
||||
Create the purchase request below minimal::
|
||||
|
||||
>>> ctx = config.context
|
||||
>>> set_user(0)
|
||||
>>> pr_id, = PurchaseRequest.create([{
|
||||
... 'product': product.id,
|
||||
... 'quantity': 30,
|
||||
... 'unit': gr,
|
||||
... 'warehouse': warehouse_loc.id,
|
||||
... }], ctx)
|
||||
>>> set_user()
|
||||
>>> purchase_request = PurchaseRequest(pr_id)
|
||||
|
||||
Create purchase::
|
||||
|
||||
>>> create_purchase = Wizard(
|
||||
... 'purchase.request.create_purchase', [purchase_request])
|
||||
>>> create_purchase.form.party = supplier
|
||||
>>> create_purchase.execute('start')
|
||||
>>> purchase_request.state
|
||||
'purchased'
|
||||
|
||||
>>> assertEqual(purchase_request.purchase_line.unit, gr)
|
||||
>>> purchase_request.purchase_line.quantity
|
||||
100.0
|
||||
|
||||
Create the purchase request wrong rounding::
|
||||
|
||||
>>> ctx = config.context
|
||||
>>> set_user(0)
|
||||
>>> pr_id, = PurchaseRequest.create([{
|
||||
... 'product': product.id,
|
||||
... 'quantity': 1001,
|
||||
... 'unit': gr,
|
||||
... 'warehouse': warehouse_loc.id,
|
||||
... }], ctx)
|
||||
>>> set_user()
|
||||
>>> purchase_request = PurchaseRequest(pr_id)
|
||||
|
||||
Create purchase::
|
||||
|
||||
>>> create_purchase = Wizard(
|
||||
... 'purchase.request.create_purchase', [purchase_request])
|
||||
>>> create_purchase.form.party = supplier
|
||||
>>> create_purchase.execute('start')
|
||||
>>> purchase_request.state
|
||||
'purchased'
|
||||
|
||||
>>> assertEqual(purchase_request.purchase_line.unit, gr)
|
||||
>>> purchase_request.purchase_line.quantity
|
||||
1050.0
|
||||
12
modules/purchase_product_quantity/tests/test_module.py
Normal file
12
modules/purchase_product_quantity/tests/test_module.py
Normal 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 PurchaseProductQuantityTestCase(ModuleTestCase):
|
||||
'Test Purchase Product Quantity module'
|
||||
module = 'purchase_product_quantity'
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/purchase_product_quantity/tests/test_scenario.py
Normal file
8
modules/purchase_product_quantity/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