first commit
This commit is contained in:
2
modules/purchase_secondary_unit/tests/__init__.py
Normal file
2
modules/purchase_secondary_unit/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,121 @@
|
||||
==================================================
|
||||
Purchase Blanket Agreement Secondary Unit 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
|
||||
|
||||
>>> today = dt.date.today()
|
||||
>>> later = today + dt.timedelta(days=30)
|
||||
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... ['purchase_secondary_unit', 'purchase_blanket_agreement'],
|
||||
... create_company, create_chart)
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> PurchaseBlanketAgreement = Model.get('purchase.blanket_agreement')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
Create supplier::
|
||||
|
||||
>>> 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.account_revenue = accounts['revenue']
|
||||
>>> account_category.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> gr, = ProductUom.find([('name', '=', 'Gram')])
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "Product"
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.list_price = Decimal('10.000')
|
||||
>>> template.purchasable = True
|
||||
>>> template.account_category = account_category
|
||||
>>> template.purchase_secondary_uom = gr
|
||||
>>> template.purchase_secondary_uom_factor = 100
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
>>> product.cost_price = Decimal('8.000')
|
||||
>>> product.save()
|
||||
|
||||
Create purchase blanket agreement::
|
||||
|
||||
>>> blanket_agreement = PurchaseBlanketAgreement()
|
||||
>>> blanket_agreement.supplier = supplier
|
||||
>>> blanket_agreement.from_date = today
|
||||
>>> blanket_agreement.to_date = later
|
||||
>>> blanket_agreement_line = blanket_agreement.lines.new()
|
||||
>>> blanket_agreement_line.product = product
|
||||
>>> blanket_agreement_line.quantity = 800.0
|
||||
>>> blanket_agreement_line.unit = gr
|
||||
>>> blanket_agreement_line.unit_price = Decimal('7.000')
|
||||
>>> blanket_agreement.click('run')
|
||||
>>> blanket_agreement.state
|
||||
'running'
|
||||
|
||||
Create purchase from blanket agreement::
|
||||
|
||||
>>> create_purchase = Wizard(
|
||||
... 'purchase.blanket_agreement.create_purchase', [blanket_agreement])
|
||||
>>> assertEqual(create_purchase.form.lines[0].unit, gr)
|
||||
>>> create_purchase.execute('create_purchase')
|
||||
|
||||
>>> purchase, = create_purchase.actions[0]
|
||||
>>> line, = purchase.lines
|
||||
>>> assertEqual(line.product, product)
|
||||
|
||||
>>> assertEqual(line.secondary_unit, gr)
|
||||
>>> line.secondary_quantity
|
||||
800.0
|
||||
>>> line.secondary_unit_price
|
||||
Decimal('7.0000')
|
||||
|
||||
>>> assertEqual(line.unit, unit)
|
||||
>>> line.quantity
|
||||
8.0
|
||||
>>> line.unit_price
|
||||
Decimal('700.0000')
|
||||
|
||||
>>> line.secondary_quantity = 300.0
|
||||
>>> purchase.save()
|
||||
|
||||
>>> blanket_agreement.reload()
|
||||
>>> blanket_agreement_line, = blanket_agreement.lines
|
||||
>>> blanket_agreement_line.remaining_quantity
|
||||
800.0
|
||||
|
||||
Confirm purchase::
|
||||
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.click('confirm')
|
||||
>>> purchase.state
|
||||
'processing'
|
||||
|
||||
>>> blanket_agreement_line.reload()
|
||||
>>> blanket_agreement_line.remaining_quantity
|
||||
500.0
|
||||
@@ -0,0 +1,100 @@
|
||||
============================================
|
||||
Purchase Requisition Secondary Unit 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
|
||||
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules([
|
||||
... 'purchase_secondary_unit',
|
||||
... 'purchase_request',
|
||||
... 'purchase_requisition'],
|
||||
... create_company, create_chart)
|
||||
|
||||
>>> Employee = Model.get('company.employee')
|
||||
>>> 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')
|
||||
>>> PurchaseRequisition = Model.get('purchase.requisition')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
Create employee::
|
||||
|
||||
>>> party = Party(name="Employee")
|
||||
>>> party.save()
|
||||
>>> employee = Employee(party=party)
|
||||
>>> employee.save()
|
||||
|
||||
Create supplier::
|
||||
|
||||
>>> 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::
|
||||
|
||||
>>> unit, = ProductUom.find([('name', '=', "Unit")])
|
||||
>>> kg, = ProductUom.find([('name', '=', "Kilogram")])
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "Product"
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.purchasable = True
|
||||
>>> template.account_category = account_category
|
||||
>>> template.purchase_secondary_uom = kg
|
||||
>>> template.purchase_secondary_uom_factor = 2
|
||||
>>> product, = template.products
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Create a purchase requisition using secondary unit::
|
||||
|
||||
>>> requisition = PurchaseRequisition()
|
||||
>>> requisition.employee = employee
|
||||
>>> requisition.supply_date = today
|
||||
>>> line = requisition.lines.new()
|
||||
>>> line.product = product
|
||||
>>> line.unit = kg
|
||||
>>> line.quantity = 6
|
||||
>>> line.unit_price = Decimal('100.0000')
|
||||
>>> requisition.click('wait')
|
||||
>>> requisition.click('approve')
|
||||
>>> requisition.state
|
||||
'processing'
|
||||
|
||||
Create Purchase order from Request::
|
||||
|
||||
>>> request, = PurchaseRequest.find([('state', '=', 'draft')])
|
||||
>>> create_purchase = Wizard('purchase.request.create_purchase', [request])
|
||||
>>> create_purchase.form.party = supplier
|
||||
>>> create_purchase.execute('start')
|
||||
>>> request.state
|
||||
'purchased'
|
||||
>>> assertEqual(request.purchase_line.unit, unit)
|
||||
>>> request.purchase_line.quantity
|
||||
3.0
|
||||
>>> request.purchase_line.unit_price
|
||||
Decimal('200.0000')
|
||||
@@ -0,0 +1,157 @@
|
||||
================================
|
||||
Purchase Secondary Unit 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, assertEqual
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules([
|
||||
... 'purchase_amendment',
|
||||
... 'purchase_secondary_unit',
|
||||
... 'account_invoice_secondary_unit',
|
||||
... 'stock_secondary_unit'],
|
||||
... create_company, create_chart)
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
Create supplier::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.save()
|
||||
|
||||
Create account categories::
|
||||
|
||||
>>> 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")])
|
||||
>>> gr, = ProductUom.find([('name', '=', "Gram")])
|
||||
>>> kg, = ProductUom.find([('name', '=', "Kilogram")])
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'product'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.purchasable = True
|
||||
>>> template.purchase_secondary_uom = gr
|
||||
>>> template.purchase_secondary_uom_factor = 100
|
||||
>>> template.purchase_secondary_uom_rate
|
||||
0.01
|
||||
>>> product_supplier = template.product_suppliers.new()
|
||||
>>> product_supplier.party = supplier
|
||||
>>> product_supplier.purchase_secondary_uom = gr
|
||||
>>> product_supplier.purchase_secondary_uom_factor = 200
|
||||
>>> product_supplier.purchase_secondary_uom_rate
|
||||
0.005
|
||||
>>> price = product_supplier.prices.new()
|
||||
>>> price.quantity = 0
|
||||
>>> price.unit_price = Decimal('3')
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
>>> product_supplier, = template.product_suppliers
|
||||
|
||||
Purchase product::
|
||||
|
||||
>>> Purchase = Model.get('purchase.purchase')
|
||||
>>> purchase = Purchase()
|
||||
>>> purchase.party = supplier
|
||||
>>> line = purchase.lines.new()
|
||||
>>> line.type = 'comment'
|
||||
>>> line.description = 'Comment'
|
||||
>>> line = purchase.lines.new()
|
||||
>>> line.product = product
|
||||
>>> line.quantity = 10
|
||||
|
||||
Check secondary unit::
|
||||
|
||||
>>> assertEqual(line.secondary_unit, gr)
|
||||
>>> line.secondary_quantity
|
||||
2000.0
|
||||
>>> line.secondary_quantity = None
|
||||
>>> line.secondary_unit = kg
|
||||
>>> line.secondary_quantity
|
||||
2.0
|
||||
>>> line.secondary_unit_price
|
||||
Decimal('15.0000')
|
||||
>>> line.secondary_unit_price = Decimal('20')
|
||||
>>> line.unit_price
|
||||
Decimal('4.0000')
|
||||
>>> line.secondary_quantity = 2000
|
||||
>>> line.quantity
|
||||
10000.0
|
||||
>>> line.secondary_unit = gr
|
||||
>>> line.quantity
|
||||
10.0
|
||||
|
||||
Confirm purchase::
|
||||
|
||||
>>> line.secondary_unit = kg
|
||||
>>> line.quantity = 10
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.click('confirm')
|
||||
>>> purchase.invoice_state
|
||||
'pending'
|
||||
>>> purchase.shipment_state
|
||||
'waiting'
|
||||
|
||||
Check secondary unit on invoice::
|
||||
|
||||
>>> invoice, = purchase.invoices
|
||||
>>> line, = invoice.lines
|
||||
>>> assertEqual(line.secondary_unit, kg)
|
||||
>>> line.secondary_quantity
|
||||
2.0
|
||||
>>> line.secondary_unit_price
|
||||
Decimal('15.0000')
|
||||
|
||||
Check secondary unit on move::
|
||||
|
||||
>>> move, = purchase.moves
|
||||
>>> assertEqual(move.secondary_unit, kg)
|
||||
>>> move.secondary_quantity
|
||||
2.0
|
||||
>>> move.secondary_unit_price
|
||||
Decimal('15.0000')
|
||||
|
||||
Add an amendment::
|
||||
|
||||
>>> amendment = purchase.amendments.new()
|
||||
>>> line = amendment.lines.new()
|
||||
>>> line.action = 'line'
|
||||
>>> line.line = purchase.lines[-1]
|
||||
>>> line.quantity = 1
|
||||
>>> line.unit = kg
|
||||
>>> line.unit_price = Decimal('45.0000')
|
||||
>>> amendment.click('validate_amendment')
|
||||
|
||||
>>> purchase.reload()
|
||||
>>> line = purchase.lines[-1]
|
||||
>>> line.quantity
|
||||
5.0
|
||||
>>> line.secondary_quantity
|
||||
1.0
|
||||
>>> line.unit_price
|
||||
Decimal('9.0000')
|
||||
>>> line.secondary_unit_price
|
||||
Decimal('45.0000')
|
||||
15
modules/purchase_secondary_unit/tests/test_module.py
Normal file
15
modules/purchase_secondary_unit/tests/test_module.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# 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 PurchaseSecondaryUnitTestCase(ModuleTestCase):
|
||||
'Test Purchase Secondary Unit module'
|
||||
module = 'purchase_secondary_unit'
|
||||
extras = [
|
||||
'account_invoice_secondary_unit', 'stock_secondary_unit',
|
||||
'purchase_blanket_agreement']
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/purchase_secondary_unit/tests/test_scenario.py
Normal file
8
modules/purchase_secondary_unit/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