first commit
This commit is contained in:
2
modules/purchase/tests/__init__.py
Normal file
2
modules/purchase/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.
|
||||
BIN
modules/purchase/tests/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
modules/purchase/tests/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
modules/purchase/tests/__pycache__/test_module.cpython-311.pyc
Normal file
BIN
modules/purchase/tests/__pycache__/test_module.cpython-311.pyc
Normal file
Binary file not shown.
BIN
modules/purchase/tests/__pycache__/test_scenario.cpython-311.pyc
Normal file
BIN
modules/purchase/tests/__pycache__/test_scenario.cpython-311.pyc
Normal file
Binary file not shown.
621
modules/purchase/tests/scenario_purchase.rst
Normal file
621
modules/purchase/tests/scenario_purchase.rst
Normal file
@@ -0,0 +1,621 @@
|
||||
=================
|
||||
Purchase Scenario
|
||||
=================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Report
|
||||
>>> from trytond.modules.account.tests.tools import (
|
||||
... create_chart, create_fiscalyear, create_tax, 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, assertEqual, set_user
|
||||
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('purchase', create_company, create_chart)
|
||||
|
||||
>>> Employee = Model.get('company.employee')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> User = Model.get('res.user')
|
||||
|
||||
Set employee::
|
||||
|
||||
>>> employee_party = Party(name="Employee")
|
||||
>>> employee_party.save()
|
||||
>>> employee = Employee(party=employee_party)
|
||||
>>> employee.save()
|
||||
>>> user = User(config.user)
|
||||
>>> user.employees.append(employee)
|
||||
>>> user.employee = employee
|
||||
>>> user.save()
|
||||
>>> set_user(user.id)
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
||||
... create_fiscalyear(today=today))
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> revenue = accounts['revenue']
|
||||
>>> expense = accounts['expense']
|
||||
>>> cash = accounts['cash']
|
||||
|
||||
>>> 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 = cash
|
||||
>>> payment_method.debit_account = cash
|
||||
>>> payment_method.save()
|
||||
|
||||
Create tax::
|
||||
|
||||
>>> tax = create_tax(Decimal('.10'))
|
||||
>>> tax.save()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.customer_code = '1234'
|
||||
>>> supplier.save()
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.save()
|
||||
|
||||
Create account categories::
|
||||
|
||||
>>> 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()
|
||||
|
||||
>>> account_category_tax, = account_category.duplicate()
|
||||
>>> account_category_tax.supplier_taxes.append(tax)
|
||||
>>> account_category_tax.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.list_price = Decimal('10')
|
||||
>>> template.cost_price_method = 'fixed'
|
||||
>>> template.account_category = account_category_tax
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'service'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'service'
|
||||
>>> template.purchasable = True
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.cost_price_method = 'fixed'
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> service, = template.products
|
||||
|
||||
Create payment term::
|
||||
|
||||
>>> payment_term = create_payment_term()
|
||||
>>> payment_term.save()
|
||||
|
||||
Create an Inventory::
|
||||
|
||||
>>> Inventory = Model.get('stock.inventory')
|
||||
>>> Location = Model.get('stock.location')
|
||||
>>> storage, = Location.find([
|
||||
... ('code', '=', 'STO'),
|
||||
... ])
|
||||
>>> inventory = Inventory()
|
||||
>>> inventory.location = storage
|
||||
>>> inventory_line = inventory.lines.new(product=product)
|
||||
>>> inventory_line.quantity = 100.0
|
||||
>>> inventory_line.expected_quantity = 0.0
|
||||
>>> inventory.click('confirm')
|
||||
>>> inventory.state
|
||||
'done'
|
||||
|
||||
Purchase 5 products::
|
||||
|
||||
>>> Purchase = Model.get('purchase.purchase')
|
||||
>>> PurchaseLine = Model.get('purchase.line')
|
||||
>>> purchase = Purchase()
|
||||
>>> purchase.party = supplier
|
||||
>>> purchase.payment_term = payment_term
|
||||
>>> purchase.invoice_method = 'order'
|
||||
>>> purchase_line = PurchaseLine()
|
||||
>>> purchase.lines.append(purchase_line)
|
||||
>>> purchase_line.product = product
|
||||
>>> purchase_line.quantity = 2.0
|
||||
>>> purchase_line.unit_price = Decimal('5.0000')
|
||||
>>> purchase_line = PurchaseLine()
|
||||
>>> purchase.lines.append(purchase_line)
|
||||
>>> purchase_line.type = 'comment'
|
||||
>>> purchase_line.description = 'Comment'
|
||||
>>> purchase_line = PurchaseLine()
|
||||
>>> purchase.lines.append(purchase_line)
|
||||
>>> purchase_line.product = product
|
||||
>>> purchase_line.quantity = 3.0
|
||||
>>> purchase_line.unit_price = Decimal('5.0000')
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.untaxed_amount, purchase.tax_amount, purchase.total_amount
|
||||
(Decimal('25.00'), Decimal('2.50'), Decimal('27.50'))
|
||||
>>> assertEqual(purchase.quoted_by, employee)
|
||||
>>> purchase.click('confirm')
|
||||
>>> purchase.untaxed_amount, purchase.tax_amount, purchase.total_amount
|
||||
(Decimal('25.00'), Decimal('2.50'), Decimal('27.50'))
|
||||
>>> assertEqual(purchase.confirmed_by, employee)
|
||||
>>> purchase.state
|
||||
'processing'
|
||||
>>> purchase.shipment_state
|
||||
'waiting'
|
||||
>>> purchase.invoice_state
|
||||
'pending'
|
||||
>>> len(purchase.moves), len(purchase.shipment_returns), len(purchase.invoices)
|
||||
(2, 0, 1)
|
||||
>>> invoice, = purchase.invoices
|
||||
>>> assertEqual(invoice.origins, purchase.rec_name)
|
||||
>>> invoice.untaxed_amount, invoice.tax_amount, invoice.total_amount
|
||||
(Decimal('25.00'), Decimal('2.50'), Decimal('27.50'))
|
||||
|
||||
Invoice line must be linked to stock move::
|
||||
|
||||
>>> invoice_line1, invoice_line2 = sorted(
|
||||
... invoice.lines, key=lambda l: l.quantity or 0)
|
||||
>>> stock_move1, stock_move2 = sorted(purchase.moves,
|
||||
... key=lambda m: m.quantity)
|
||||
>>> assertEqual(invoice_line1.stock_moves, [stock_move1])
|
||||
>>> assertEqual(stock_move1.invoice_lines, [invoice_line1])
|
||||
>>> assertEqual(invoice_line2.stock_moves, [stock_move2])
|
||||
>>> assertEqual(stock_move2.invoice_lines, [invoice_line2])
|
||||
|
||||
Check actual quantity::
|
||||
|
||||
>>> for line in purchase.lines:
|
||||
... assertEqual(line.quantity, line.actual_quantity)
|
||||
|
||||
Post invoice and check no new invoices::
|
||||
|
||||
>>> invoice.invoice_date = today
|
||||
>>> invoice.click('post')
|
||||
>>> purchase.reload()
|
||||
>>> purchase.shipment_state
|
||||
'waiting'
|
||||
>>> purchase.invoice_state
|
||||
'awaiting payment'
|
||||
>>> len(purchase.moves), len(purchase.shipment_returns), len(purchase.invoices)
|
||||
(2, 0, 1)
|
||||
|
||||
Purchase 5 products with an invoice method 'on shipment'::
|
||||
|
||||
>>> purchase = Purchase()
|
||||
>>> purchase.party = supplier
|
||||
>>> purchase.payment_term = payment_term
|
||||
>>> purchase.invoice_method = 'shipment'
|
||||
>>> purchase_line = PurchaseLine()
|
||||
>>> purchase.lines.append(purchase_line)
|
||||
>>> purchase_line.product = product
|
||||
>>> purchase_line.quantity = 2.0
|
||||
>>> purchase_line = PurchaseLine()
|
||||
>>> purchase.lines.append(purchase_line)
|
||||
>>> purchase_line.type = 'comment'
|
||||
>>> purchase_line.description = 'Comment'
|
||||
>>> purchase_line = PurchaseLine()
|
||||
>>> purchase.lines.append(purchase_line)
|
||||
>>> purchase_line.product = product
|
||||
>>> purchase_line.quantity = 3.0
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.click('confirm')
|
||||
>>> purchase.state
|
||||
'processing'
|
||||
>>> purchase.shipment_state
|
||||
'waiting'
|
||||
>>> purchase.invoice_state
|
||||
'none'
|
||||
>>> len(purchase.moves), len(purchase.shipment_returns), len(purchase.invoices)
|
||||
(2, 0, 0)
|
||||
|
||||
Not yet linked to invoice lines::
|
||||
|
||||
>>> stock_move1, stock_move2 = sorted(purchase.moves,
|
||||
... key=lambda m: m.quantity)
|
||||
>>> len(stock_move1.invoice_lines)
|
||||
0
|
||||
>>> len(stock_move2.invoice_lines)
|
||||
0
|
||||
|
||||
Validate Shipments::
|
||||
|
||||
>>> Move = Model.get('stock.move')
|
||||
>>> ShipmentIn = Model.get('stock.shipment.in')
|
||||
>>> shipment = ShipmentIn()
|
||||
>>> shipment.supplier = supplier
|
||||
>>> for move in purchase.moves:
|
||||
... incoming_move = Move(id=move.id)
|
||||
... shipment.incoming_moves.append(incoming_move)
|
||||
>>> shipment.save()
|
||||
>>> assertEqual(shipment.origins, purchase.rec_name)
|
||||
>>> shipment.click('receive')
|
||||
>>> shipment.click('do')
|
||||
>>> purchase.reload()
|
||||
>>> purchase.shipment_state
|
||||
'received'
|
||||
>>> len(purchase.shipments), len(purchase.shipment_returns)
|
||||
(1, 0)
|
||||
|
||||
Open supplier invoice::
|
||||
|
||||
>>> purchase.invoice_state
|
||||
'pending'
|
||||
>>> invoice, = purchase.invoices
|
||||
>>> invoice.type
|
||||
'in'
|
||||
>>> invoice_line1, invoice_line2 = sorted(invoice.lines,
|
||||
... key=lambda l: l.quantity or 0)
|
||||
>>> for line in invoice.lines:
|
||||
... line.quantity = 1
|
||||
... line.save()
|
||||
>>> invoice.invoice_date = today
|
||||
>>> invoice.click('post')
|
||||
|
||||
Invoice lines must be linked to each stock moves::
|
||||
|
||||
>>> assertEqual(invoice_line1.stock_moves, [stock_move1])
|
||||
>>> assertEqual(invoice_line2.stock_moves, [stock_move2])
|
||||
|
||||
Check second invoices::
|
||||
|
||||
>>> purchase.reload()
|
||||
>>> len(purchase.invoices)
|
||||
2
|
||||
>>> sum(l.quantity for i in purchase.invoices for l in i.lines)
|
||||
5.0
|
||||
|
||||
Create the report::
|
||||
|
||||
>>> purchase_report = Report('purchase.purchase')
|
||||
>>> ext, _, _, name = purchase_report.execute([purchase], {})
|
||||
>>> ext
|
||||
'odt'
|
||||
>>> name
|
||||
'Purchase-2'
|
||||
|
||||
Create a Return::
|
||||
|
||||
>>> return_ = Purchase()
|
||||
>>> return_.party = supplier
|
||||
>>> return_.payment_term = payment_term
|
||||
>>> return_.invoice_method = 'shipment'
|
||||
>>> return_line = PurchaseLine()
|
||||
>>> return_.lines.append(return_line)
|
||||
>>> return_line.product = product
|
||||
>>> return_line.quantity = -4.
|
||||
>>> return_line = PurchaseLine()
|
||||
>>> return_.lines.append(return_line)
|
||||
>>> return_line.type = 'comment'
|
||||
>>> return_line.description = 'Comment'
|
||||
>>> return_.click('quote')
|
||||
>>> return_.click('confirm')
|
||||
>>> return_.state
|
||||
'processing'
|
||||
>>> return_.shipment_state
|
||||
'waiting'
|
||||
>>> return_.invoice_state
|
||||
'none'
|
||||
>>> (len(return_.shipments), len(return_.shipment_returns),
|
||||
... len(return_.invoices))
|
||||
(0, 1, 0)
|
||||
|
||||
Check Return Shipments::
|
||||
|
||||
>>> ShipmentReturn = Model.get('stock.shipment.in.return')
|
||||
>>> ship_return, = return_.shipment_returns
|
||||
>>> ship_return.state
|
||||
'waiting'
|
||||
>>> move_return, = ship_return.moves
|
||||
>>> move_return.product.rec_name
|
||||
'product'
|
||||
>>> move_return.quantity
|
||||
4.0
|
||||
>>> ship_return.click('assign_try')
|
||||
>>> ship_return.click('do')
|
||||
>>> ship_return.state
|
||||
'done'
|
||||
>>> return_.reload()
|
||||
>>> return_.state
|
||||
'processing'
|
||||
>>> return_.shipment_state
|
||||
'received'
|
||||
>>> return_.invoice_state
|
||||
'pending'
|
||||
|
||||
Open supplier credit note::
|
||||
|
||||
>>> credit_note, = return_.invoices
|
||||
>>> credit_note.type
|
||||
'in'
|
||||
>>> len(credit_note.lines)
|
||||
1
|
||||
>>> sum(l.quantity for l in credit_note.lines)
|
||||
-4.0
|
||||
>>> credit_note.invoice_date = today
|
||||
>>> credit_note.click('post')
|
||||
|
||||
Mixing return and purchase::
|
||||
|
||||
>>> mix = Purchase()
|
||||
>>> mix.party = supplier
|
||||
>>> mix.payment_term = payment_term
|
||||
>>> mix.invoice_method = 'order'
|
||||
>>> mixline = PurchaseLine()
|
||||
>>> mix.lines.append(mixline)
|
||||
>>> mixline.product = product
|
||||
>>> mixline.quantity = 7.
|
||||
>>> mixline_comment = PurchaseLine()
|
||||
>>> mix.lines.append(mixline_comment)
|
||||
>>> mixline_comment.type = 'comment'
|
||||
>>> mixline_comment.description = 'Comment'
|
||||
>>> mixline2 = PurchaseLine()
|
||||
>>> mix.lines.append(mixline2)
|
||||
>>> mixline2.product = product
|
||||
>>> mixline2.quantity = -2.
|
||||
>>> mix.click('quote')
|
||||
>>> mix.click('confirm')
|
||||
>>> mix.state
|
||||
'processing'
|
||||
>>> mix.shipment_state
|
||||
'waiting'
|
||||
>>> mix.invoice_state
|
||||
'pending'
|
||||
>>> len(mix.moves), len(mix.shipment_returns), len(mix.invoices)
|
||||
(2, 1, 1)
|
||||
|
||||
Checking Shipments::
|
||||
|
||||
>>> mix_return, = mix.shipment_returns
|
||||
>>> mix_shipment = ShipmentIn()
|
||||
>>> mix_shipment.supplier = supplier
|
||||
>>> for move in mix.moves:
|
||||
... if move.id in [m.id for m in mix_return.moves]:
|
||||
... continue
|
||||
... incoming_move = Move(id=move.id)
|
||||
... mix_shipment.incoming_moves.append(incoming_move)
|
||||
>>> mix_shipment.click('receive')
|
||||
>>> mix_shipment.click('do')
|
||||
>>> mix.reload()
|
||||
>>> len(mix.shipments)
|
||||
1
|
||||
|
||||
>>> mix_return.click('wait')
|
||||
>>> mix_return.click('assign_try')
|
||||
>>> mix_return.click('do')
|
||||
>>> move_return, = mix_return.moves
|
||||
>>> move_return.product.rec_name
|
||||
'product'
|
||||
>>> move_return.quantity
|
||||
2.0
|
||||
|
||||
Checking the invoice::
|
||||
|
||||
>>> mix.reload()
|
||||
>>> mix_invoice, = mix.invoices
|
||||
>>> mix_invoice.type
|
||||
'in'
|
||||
>>> len(mix_invoice.lines)
|
||||
2
|
||||
>>> sorted(l.quantity for l in mix_invoice.lines)
|
||||
[-2.0, 7.0]
|
||||
>>> mix_invoice.invoice_date = today
|
||||
>>> mix_invoice.click('post')
|
||||
|
||||
Mixing stuff with an invoice method 'on shipment'::
|
||||
|
||||
>>> mix = Purchase()
|
||||
>>> mix.party = supplier
|
||||
>>> mix.payment_term = payment_term
|
||||
>>> mix.invoice_method = 'shipment'
|
||||
>>> mixline = PurchaseLine()
|
||||
>>> mix.lines.append(mixline)
|
||||
>>> mixline.product = product
|
||||
>>> mixline.quantity = 6.
|
||||
>>> mixline_comment = PurchaseLine()
|
||||
>>> mix.lines.append(mixline_comment)
|
||||
>>> mixline_comment.type = 'comment'
|
||||
>>> mixline_comment.description = 'Comment'
|
||||
>>> mixline2 = PurchaseLine()
|
||||
>>> mix.lines.append(mixline2)
|
||||
>>> mixline2.product = product
|
||||
>>> mixline2.quantity = -3.
|
||||
>>> mix.click('quote')
|
||||
>>> mix.click('confirm')
|
||||
>>> mix.state
|
||||
'processing'
|
||||
>>> mix.shipment_state
|
||||
'waiting'
|
||||
>>> mix.invoice_state
|
||||
'none'
|
||||
>>> len(mix.moves), len(mix.shipment_returns), len(mix.invoices)
|
||||
(2, 1, 0)
|
||||
|
||||
Checking Shipments::
|
||||
|
||||
>>> mix_return, = mix.shipment_returns
|
||||
>>> mix_shipment = ShipmentIn()
|
||||
>>> mix_shipment.supplier = supplier
|
||||
>>> for move in mix.moves:
|
||||
... if move.id in [m.id for m in mix_return.moves]:
|
||||
... continue
|
||||
... incoming_move = Move(id=move.id)
|
||||
... mix_shipment.incoming_moves.append(incoming_move)
|
||||
>>> mix_shipment.click('receive')
|
||||
>>> mix_shipment.click('do')
|
||||
>>> mix.reload()
|
||||
>>> len(mix.shipments)
|
||||
1
|
||||
|
||||
>>> mix_return.click('wait')
|
||||
>>> mix_return.click('assign_try')
|
||||
>>> mix_return.click('do')
|
||||
>>> move_return, = mix_return.moves
|
||||
>>> move_return.product.rec_name
|
||||
'product'
|
||||
>>> move_return.quantity
|
||||
3.0
|
||||
|
||||
Purchase services::
|
||||
|
||||
>>> service_purchase = Purchase()
|
||||
>>> service_purchase.party = supplier
|
||||
>>> service_purchase.payment_term = payment_term
|
||||
>>> purchase_line = service_purchase.lines.new()
|
||||
>>> purchase_line.product = service
|
||||
>>> purchase_line.quantity = 1
|
||||
>>> purchase_line.unit_price = Decimal('10.0000')
|
||||
>>> service_purchase.save()
|
||||
>>> service_purchase.click('quote')
|
||||
>>> service_purchase.click('confirm')
|
||||
>>> service_purchase.state
|
||||
'processing'
|
||||
>>> service_purchase.shipment_state
|
||||
'none'
|
||||
>>> service_purchase.invoice_state
|
||||
'pending'
|
||||
>>> service_invoice, = service_purchase.invoices
|
||||
|
||||
Pay the service invoice::
|
||||
|
||||
>>> service_invoice.invoice_date = today
|
||||
>>> service_invoice.click('post')
|
||||
>>> pay = service_invoice.click('pay')
|
||||
>>> pay.form.payment_method = payment_method
|
||||
>>> pay.form.amount = service_invoice.total_amount
|
||||
>>> pay.execute('choice')
|
||||
>>> service_invoice.reload()
|
||||
>>> service_invoice.state
|
||||
'paid'
|
||||
|
||||
Check service purchase states::
|
||||
|
||||
>>> service_purchase.reload()
|
||||
>>> service_purchase.invoice_state
|
||||
'paid'
|
||||
>>> service_purchase.shipment_state
|
||||
'none'
|
||||
>>> service_purchase.state
|
||||
'done'
|
||||
|
||||
Create a purchase to be invoiced on shipment partially and check correctly
|
||||
linked to invoices::
|
||||
|
||||
>>> purchase = Purchase()
|
||||
>>> purchase.party = supplier
|
||||
>>> purchase.payment_term = payment_term
|
||||
>>> purchase.invoice_method = 'shipment'
|
||||
>>> line = purchase.lines.new()
|
||||
>>> line.product = product
|
||||
>>> line.quantity = 10.0
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.click('confirm')
|
||||
>>> shipment = ShipmentIn()
|
||||
>>> shipment.supplier = supplier
|
||||
>>> for move in purchase.moves:
|
||||
... incoming_move = Move(id=move.id)
|
||||
... incoming_move.quantity = 5.0
|
||||
... shipment.incoming_moves.append(incoming_move)
|
||||
>>> shipment.save()
|
||||
>>> for move in shipment.inventory_moves:
|
||||
... move.quantity = 5.0
|
||||
>>> shipment.click('receive')
|
||||
>>> shipment.click('do')
|
||||
>>> purchase.reload()
|
||||
>>> invoice, = purchase.invoices
|
||||
>>> invoice_line, = invoice.lines
|
||||
>>> invoice_line.quantity
|
||||
5.0
|
||||
>>> stock_move, = invoice_line.stock_moves
|
||||
>>> stock_move.quantity
|
||||
5.0
|
||||
>>> stock_move.state
|
||||
'done'
|
||||
|
||||
Create a purchase to be invoiced on order, partially send it and check
|
||||
correctly linked to invoices::
|
||||
|
||||
>>> purchase = Purchase()
|
||||
>>> purchase.party = supplier
|
||||
>>> purchase.payment_term = payment_term
|
||||
>>> purchase.invoice_method = 'order'
|
||||
>>> line = purchase.lines.new()
|
||||
>>> line.product = product
|
||||
>>> line.quantity = 10.0
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.click('confirm')
|
||||
>>> shipment = ShipmentIn()
|
||||
>>> shipment.supplier = supplier
|
||||
>>> for move in purchase.moves:
|
||||
... incoming_move = Move(id=move.id)
|
||||
... incoming_move.quantity = 8.0
|
||||
... shipment.incoming_moves.append(incoming_move)
|
||||
>>> shipment.save()
|
||||
>>> for move in shipment.inventory_moves:
|
||||
... move.quantity = 8.0
|
||||
>>> shipment.click('receive')
|
||||
>>> shipment.click('do')
|
||||
>>> purchase.reload()
|
||||
>>> invoice, = purchase.invoices
|
||||
>>> invoice_line, = invoice.lines
|
||||
>>> invoice_line.quantity
|
||||
10.0
|
||||
>>> draft_stock_move, stock_move = sorted(
|
||||
... invoice_line.stock_moves, key=lambda m: m.quantity)
|
||||
>>> draft_stock_move.quantity
|
||||
2.0
|
||||
>>> draft_stock_move.state
|
||||
'draft'
|
||||
>>> stock_move.quantity
|
||||
8.0
|
||||
>>> stock_move.state
|
||||
'done'
|
||||
|
||||
Deleting a line from a invoice should recreate it::
|
||||
|
||||
>>> purchase = Purchase()
|
||||
>>> purchase.party = customer
|
||||
>>> line = purchase.lines.new()
|
||||
>>> line.product = product
|
||||
>>> line.quantity = 10.0
|
||||
>>> line.unit_price = Decimal('5.0000')
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.click('confirm')
|
||||
>>> invoice, = purchase.invoices
|
||||
>>> invoice_line, = invoice.lines
|
||||
>>> invoice.lines.remove(invoice_line)
|
||||
>>> invoice.invoice_date = today
|
||||
>>> invoice.click('post')
|
||||
>>> purchase.reload()
|
||||
>>> new_invoice, = purchase.invoices
|
||||
>>> new_invoice.number
|
||||
>>> len(new_invoice.lines)
|
||||
1
|
||||
@@ -0,0 +1,52 @@
|
||||
========================================
|
||||
Purchase Copy Product Suppliers Scenario
|
||||
========================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('purchase', create_company)
|
||||
|
||||
Create party::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.save()
|
||||
|
||||
Create a product with suppliers::
|
||||
|
||||
>>> 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.list_price = Decimal('10')
|
||||
>>> template.cost_price_method = 'fixed'
|
||||
>>> product_supplier = template.product_suppliers.new()
|
||||
>>> product_supplier.party = supplier
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
>>> product_supplier = product.product_suppliers.new()
|
||||
>>> product_supplier.party = supplier
|
||||
>>> assertEqual(product_supplier.template, template)
|
||||
>>> product.save()
|
||||
|
||||
Supplier is copied when copying the template::
|
||||
|
||||
>>> template_copy, = template.duplicate()
|
||||
>>> product_copy, = template_copy.products
|
||||
>>> len(template_copy.product_suppliers)
|
||||
2
|
||||
>>> len(product_copy.product_suppliers)
|
||||
1
|
||||
59
modules/purchase/tests/scenario_purchase_default_taxes.rst
Normal file
59
modules/purchase/tests/scenario_purchase_default_taxes.rst
Normal file
@@ -0,0 +1,59 @@
|
||||
===========================
|
||||
Purchase with Default Taxes
|
||||
===========================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.account.tests.tools import (
|
||||
... create_chart, create_tax, 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', create_company, create_chart)
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> Purchase = Model.get('purchase.purchase')
|
||||
>>> Tax = Model.get('account.tax')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
Create tax::
|
||||
|
||||
>>> tax = create_tax(Decimal('.10'))
|
||||
>>> tax.save()
|
||||
>>> accounts['expense'].taxes.append(Tax(tax.id))
|
||||
>>> accounts['expense'].save()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> supplier = Party(name="Supplier")
|
||||
>>> supplier.save()
|
||||
|
||||
Create a purchase without product::
|
||||
|
||||
>>> purchase = Purchase(party=supplier)
|
||||
>>> line = purchase.lines.new()
|
||||
>>> assertEqual(line.taxes, [tax])
|
||||
>>> line.quantity = 1
|
||||
>>> line.unit_price = Decimal('100.0000')
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.total_amount
|
||||
Decimal('110.00')
|
||||
>>> purchase.click('confirm')
|
||||
>>> purchase.state
|
||||
'processing'
|
||||
|
||||
Check invoice::
|
||||
|
||||
>>> invoice, = purchase.invoices
|
||||
>>> invoice.total_amount
|
||||
Decimal('110.00')
|
||||
>>> line, = invoice.lines
|
||||
>>> assertEqual(line.account, accounts['expense'])
|
||||
48
modules/purchase/tests/scenario_purchase_empty.rst
Normal file
48
modules/purchase/tests/scenario_purchase_empty.rst
Normal file
@@ -0,0 +1,48 @@
|
||||
=======================
|
||||
Purchase Empty Scenario
|
||||
=======================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.account.tests.tools import create_chart
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('purchase', create_company, create_chart)
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.save()
|
||||
|
||||
Create empty purchase::
|
||||
|
||||
>>> Purchase = Model.get('purchase.purchase')
|
||||
>>> purchase = Purchase()
|
||||
>>> purchase.party = supplier
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.state
|
||||
'quotation'
|
||||
>>> purchase.untaxed_amount
|
||||
Decimal('0')
|
||||
>>> purchase.tax_amount
|
||||
Decimal('0')
|
||||
>>> purchase.total_amount
|
||||
Decimal('0')
|
||||
>>> purchase.click('confirm')
|
||||
>>> purchase.state
|
||||
'done'
|
||||
>>> purchase.shipment_state
|
||||
'none'
|
||||
>>> len(purchase.moves)
|
||||
0
|
||||
>>> len(purchase.shipment_returns)
|
||||
0
|
||||
>>> purchase.invoice_state
|
||||
'none'
|
||||
>>> len(purchase.invoices)
|
||||
0
|
||||
103
modules/purchase/tests/scenario_purchase_line_cancelled.rst
Normal file
103
modules/purchase/tests/scenario_purchase_line_cancelled.rst
Normal file
@@ -0,0 +1,103 @@
|
||||
================================
|
||||
Purchase Line Cancelled 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('purchase', create_company, create_chart)
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> Purchase = Model.get('purchase.purchase')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
Create party::
|
||||
|
||||
>>> supplier = Party(name="Supplier")
|
||||
>>> supplier.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> account_category = ProductCategory(name="Account Category")
|
||||
>>> account_category.accounting = True
|
||||
>>> account_category.account_expense = accounts['expense']
|
||||
>>> account_category.save()
|
||||
|
||||
>>> template = ProductTemplate(name="Product")
|
||||
>>> template.default_uom, = ProductUom.find([('name', '=', "Unit")])
|
||||
>>> template.type = 'goods'
|
||||
>>> template.purchasable = True
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Purchase product::
|
||||
|
||||
>>> purchase = Purchase(party=supplier)
|
||||
>>> line = purchase.lines.new()
|
||||
>>> line.product = product
|
||||
>>> line.quantity = 1
|
||||
>>> line.unit_price = Decimal('10.0000')
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.click('confirm')
|
||||
>>> purchase.state
|
||||
'processing'
|
||||
>>> purchase.shipment_state
|
||||
'waiting'
|
||||
>>> purchase.invoice_state
|
||||
'pending'
|
||||
|
||||
Cancel stock move and invoice::
|
||||
|
||||
>>> move, = purchase.moves
|
||||
>>> move.click('cancel')
|
||||
>>> move.state
|
||||
'cancelled'
|
||||
|
||||
>>> invoice, = purchase.invoices
|
||||
>>> invoice.click('cancel')
|
||||
>>> invoice.state
|
||||
'cancelled'
|
||||
|
||||
>>> purchase.reload()
|
||||
>>> purchase.state
|
||||
'processing'
|
||||
>>> purchase.shipment_state
|
||||
'exception'
|
||||
>>> purchase.invoice_state
|
||||
'exception'
|
||||
|
||||
Ignore exceptions::
|
||||
|
||||
>>> invoice_handle_exception = purchase.click('handle_invoice_exception')
|
||||
>>> invoice_handle_exception.form.ignore_invoices.extend(
|
||||
... invoice_handle_exception.form.ignore_invoices.find())
|
||||
>>> invoice_handle_exception.execute('handle')
|
||||
|
||||
>>> purchase.invoice_state
|
||||
'none'
|
||||
|
||||
>>> shipment_handle_exception = purchase.click('handle_shipment_exception')
|
||||
>>> shipment_handle_exception.form.ignore_moves.extend(
|
||||
... shipment_handle_exception.form.ignore_moves.find())
|
||||
>>> shipment_handle_exception.execute('handle')
|
||||
|
||||
>>> purchase.shipment_state
|
||||
'none'
|
||||
|
||||
>>> purchase.state
|
||||
'done'
|
||||
@@ -0,0 +1,91 @@
|
||||
============================================
|
||||
Purchase Line Cancelled On Shipment 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('purchase', create_company, create_chart)
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> Purchase = Model.get('purchase.purchase')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
Create party::
|
||||
|
||||
>>> supplier = Party(name="Supplier")
|
||||
>>> supplier.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> account_category = ProductCategory(name="Account Category")
|
||||
>>> account_category.accounting = True
|
||||
>>> account_category.account_expense = accounts['expense']
|
||||
>>> account_category.save()
|
||||
|
||||
>>> template = ProductTemplate(name="Product")
|
||||
>>> template.default_uom, = ProductUom.find([('name', '=', "Unit")])
|
||||
>>> template.type = 'goods'
|
||||
>>> template.purchasable = True
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Purchase product::
|
||||
|
||||
>>> purchase = Purchase(party=supplier)
|
||||
>>> purchase.invoice_method = 'shipment'
|
||||
>>> line = purchase.lines.new()
|
||||
>>> line.product = product
|
||||
>>> line.quantity = 1
|
||||
>>> line.unit_price = Decimal('10.0000')
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.click('confirm')
|
||||
>>> purchase.state
|
||||
'processing'
|
||||
>>> purchase.shipment_state
|
||||
'waiting'
|
||||
>>> purchase.invoice_state
|
||||
'none'
|
||||
|
||||
Cancel stock move::
|
||||
|
||||
>>> move, = purchase.moves
|
||||
>>> move.click('cancel')
|
||||
>>> move.state
|
||||
'cancelled'
|
||||
|
||||
>>> purchase.reload()
|
||||
>>> purchase.state
|
||||
'processing'
|
||||
>>> purchase.shipment_state
|
||||
'exception'
|
||||
>>> purchase.invoice_state
|
||||
'none'
|
||||
|
||||
Ignore exception::
|
||||
|
||||
>>> shipment_handle_exception = purchase.click('handle_shipment_exception')
|
||||
>>> shipment_handle_exception.form.ignore_moves.extend(
|
||||
... shipment_handle_exception.form.ignore_moves.find())
|
||||
>>> shipment_handle_exception.execute('handle')
|
||||
|
||||
>>> purchase.shipment_state
|
||||
'none'
|
||||
|
||||
>>> purchase.state
|
||||
'done'
|
||||
90
modules/purchase/tests/scenario_purchase_manual_invoice.rst
Normal file
90
modules/purchase/tests/scenario_purchase_manual_invoice.rst
Normal file
@@ -0,0 +1,90 @@
|
||||
================================
|
||||
Purchase Manual Invoice 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('purchase', create_company, create_chart)
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> Purchase = Model.get('purchase.purchase')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
Create party::
|
||||
|
||||
>>> 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')])
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'product'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'service'
|
||||
>>> template.purchasable = True
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Purchase with manual invoice method::
|
||||
|
||||
>>> purchase = Purchase()
|
||||
>>> purchase.party = supplier
|
||||
>>> purchase.invoice_method = 'manual'
|
||||
>>> line = purchase.lines.new()
|
||||
>>> line.product = product
|
||||
>>> line.quantity = 10
|
||||
>>> line.unit_price = Decimal('5.0000')
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.click('confirm')
|
||||
>>> purchase.state
|
||||
'processing'
|
||||
>>> purchase.invoice_state
|
||||
'none'
|
||||
>>> len(purchase.invoices)
|
||||
0
|
||||
|
||||
Manually create an invoice::
|
||||
|
||||
>>> purchase.click('manual_invoice')
|
||||
>>> purchase.state
|
||||
'processing'
|
||||
>>> purchase.invoice_state
|
||||
'pending'
|
||||
|
||||
Change quantity on invoice and create a new invoice::
|
||||
|
||||
>>> invoice, = purchase.invoices
|
||||
>>> line, = invoice.lines
|
||||
>>> line.quantity = 5
|
||||
>>> invoice.save()
|
||||
|
||||
>>> len(purchase.invoices)
|
||||
1
|
||||
>>> purchase.click('manual_invoice')
|
||||
>>> len(purchase.invoices)
|
||||
2
|
||||
92
modules/purchase/tests/scenario_purchase_modify_header.rst
Normal file
92
modules/purchase/tests/scenario_purchase_modify_header.rst
Normal file
@@ -0,0 +1,92 @@
|
||||
===============================
|
||||
Purchase Modify Header Scenario
|
||||
===============================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.account.tests.tools import (
|
||||
... create_chart, create_tax, 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', create_company, create_chart)
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> expense = accounts['expense']
|
||||
|
||||
Create tax and tax rule::
|
||||
|
||||
>>> tax = create_tax(Decimal('.10'))
|
||||
>>> tax.save()
|
||||
|
||||
>>> TaxRule = Model.get('account.tax.rule')
|
||||
>>> foreign = TaxRule(name='Foreign Suppliers')
|
||||
>>> no_tax = foreign.lines.new()
|
||||
>>> no_tax.origin_tax = tax
|
||||
>>> foreign.save()
|
||||
|
||||
Create account categories::
|
||||
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> account_category = ProductCategory(name="Account Category")
|
||||
>>> account_category.accounting = True
|
||||
>>> account_category.account_expense = expense
|
||||
>>> account_category.supplier_taxes.append(tax)
|
||||
>>> 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.list_price = Decimal('10')
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.save()
|
||||
>>> another = Party(name='Another Supplier', supplier_tax_rule=foreign)
|
||||
>>> another.save()
|
||||
|
||||
Create a sale with a line::
|
||||
|
||||
>>> Purchase = Model.get('purchase.purchase')
|
||||
>>> purchase = Purchase()
|
||||
>>> purchase.party = supplier
|
||||
>>> purchase_line = purchase.lines.new()
|
||||
>>> purchase_line.product = product
|
||||
>>> purchase_line.quantity = 3
|
||||
>>> purchase_line.unit_price = Decimal('5.0000')
|
||||
>>> purchase_line_comment = purchase.lines.new(type='comment')
|
||||
>>> purchase.save()
|
||||
>>> purchase.untaxed_amount, purchase.tax_amount, purchase.total_amount
|
||||
(Decimal('15.00'), Decimal('1.50'), Decimal('16.50'))
|
||||
|
||||
Change the party::
|
||||
|
||||
>>> modify_header = purchase.click('modify_header')
|
||||
>>> assertEqual(modify_header.form.party, supplier)
|
||||
>>> modify_header.form.party = another
|
||||
>>> modify_header.execute('modify')
|
||||
|
||||
>>> purchase.party.name
|
||||
'Another Supplier'
|
||||
>>> purchase.untaxed_amount, purchase.tax_amount, purchase.total_amount
|
||||
(Decimal('15.00'), Decimal('0'), Decimal('15.00'))
|
||||
145
modules/purchase/tests/scenario_purchase_reporting.rst
Normal file
145
modules/purchase/tests/scenario_purchase_reporting.rst
Normal file
@@ -0,0 +1,145 @@
|
||||
===========================
|
||||
Purchase Reporting Scenario
|
||||
===========================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from dateutil.relativedelta import relativedelta
|
||||
|
||||
>>> 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, assertEqual
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('purchase', create_company, create_chart)
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> Purchase = Model.get('purchase.purchase')
|
||||
>>> Supplier = Model.get('purchase.reporting.supplier')
|
||||
>>> SupplierTimeseries = Model.get(
|
||||
... 'purchase.reporting.supplier.time_series')
|
||||
>>> Product = Model.get('purchase.reporting.product')
|
||||
>>> ProductTimeseries = Model.get('purchase.reporting.product.time_series')
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(create_fiscalyear())
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> expense = accounts['expense']
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> supplier1 = Party(name='Supplier1')
|
||||
>>> supplier1.save()
|
||||
>>> supplier2 = Party(name='Supplier2')
|
||||
>>> supplier2.save()
|
||||
|
||||
Create products::
|
||||
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
|
||||
>>> template1 = ProductTemplate()
|
||||
>>> template1.name = "Product1"
|
||||
>>> template1.default_uom = unit
|
||||
>>> template1.type = 'service'
|
||||
>>> template1.purchasable = True
|
||||
>>> template1.list_price = Decimal('20')
|
||||
>>> template1.save()
|
||||
>>> product1, = template1.products
|
||||
|
||||
>>> template2, = template1.duplicate(default={'name': "Product2"})
|
||||
>>> product2, = template2.products
|
||||
|
||||
Create purchases::
|
||||
|
||||
>>> purchase1 = Purchase()
|
||||
>>> purchase1.party = supplier1
|
||||
>>> purchase1.purchase_date = fiscalyear.start_date
|
||||
>>> line = purchase1.lines.new()
|
||||
>>> line.product = product1
|
||||
>>> line.quantity = 2
|
||||
>>> line.unit_price = Decimal('10.0000')
|
||||
>>> line = purchase1.lines.new()
|
||||
>>> line.product = product2
|
||||
>>> line.quantity = 1
|
||||
>>> line.unit_price = Decimal('10.0000')
|
||||
>>> purchase1.click('quote')
|
||||
>>> purchase1.click('confirm')
|
||||
|
||||
>>> purchase2 = Purchase()
|
||||
>>> purchase2.party = supplier2
|
||||
>>> purchase2.purchase_date = (
|
||||
... fiscalyear.start_date + relativedelta(months=1))
|
||||
>>> line = purchase2.lines.new()
|
||||
>>> line.product = product1
|
||||
>>> line.quantity = 1
|
||||
>>> line.unit_price = Decimal('10.0000')
|
||||
>>> purchase2.click('quote')
|
||||
>>> purchase2.click('confirm')
|
||||
|
||||
Check purchase reporting per supplier::
|
||||
|
||||
>>> context = dict(
|
||||
... from_date=fiscalyear.start_date,
|
||||
... to_date=fiscalyear.end_date,
|
||||
... period='month')
|
||||
>>> with config.set_context(context=context):
|
||||
... reports = Supplier.find([])
|
||||
... time_series = SupplierTimeseries.find([])
|
||||
>>> len(reports)
|
||||
2
|
||||
>>> with config.set_context(context=context):
|
||||
... assertEqual({(r.supplier.id, r.number, r.expense) for r in reports},
|
||||
... {(supplier1.id, 1, Decimal('30')),
|
||||
... (supplier2.id, 1, Decimal('10'))})
|
||||
>>> len(time_series)
|
||||
2
|
||||
>>> purchase1_ts_date = purchase1.purchase_date.replace(day=1)
|
||||
>>> purchase2_ts_date = purchase2.purchase_date.replace(day=1)
|
||||
>>> with config.set_context(context=context):
|
||||
... assertEqual({(r.supplier.id, r.date, r.number, r.expense)
|
||||
... for r in time_series},
|
||||
... {(supplier1.id, purchase1_ts_date, 1, Decimal('30')),
|
||||
... (supplier2.id, purchase2_ts_date, 1, Decimal('10'))})
|
||||
|
||||
Check purchase reporting per product without supplier::
|
||||
|
||||
>>> with config.set_context(context=context):
|
||||
... reports = Product.find([])
|
||||
... time_series = ProductTimeseries.find([])
|
||||
>>> len(reports)
|
||||
0
|
||||
|
||||
Check purchase reporting per product with supplier::
|
||||
|
||||
>>> context['supplier'] = supplier1.id
|
||||
>>> context['currency'] = purchase1.currency.id
|
||||
>>> with config.set_context(context=context):
|
||||
... reports = Product.find([])
|
||||
... time_series = ProductTimeseries.find([])
|
||||
>>> len(reports)
|
||||
2
|
||||
>>> with config.set_context(context=context):
|
||||
... assertEqual({(r.product.id, r.number, r.expense) for r in reports},
|
||||
... {(product1.id, 1, Decimal('20')),
|
||||
... (product2.id, 1, Decimal('10'))})
|
||||
>>> len(time_series)
|
||||
2
|
||||
>>> with config.set_context(context=context):
|
||||
... assertEqual({(r.product.id, r.date, r.number, r.expense)
|
||||
... for r in time_series},
|
||||
... {(product1.id, purchase1_ts_date, 1, Decimal('20')),
|
||||
... (product2.id, purchase1_ts_date, 1, Decimal('10'))})
|
||||
86
modules/purchase/tests/scenario_purchase_return_wizard.rst
Normal file
86
modules/purchase/tests/scenario_purchase_return_wizard.rst
Normal file
@@ -0,0 +1,86 @@
|
||||
===============================
|
||||
Purchase Return Wizard 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 (
|
||||
... set_fiscalyear_invoice_sequences)
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('purchase', create_company, create_chart)
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(create_fiscalyear())
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> expense = accounts['expense']
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> 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 = expense
|
||||
>>> account_category.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'service'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'service'
|
||||
>>> template.purchasable = True
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.cost_price_method = 'fixed'
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> service, = template.products
|
||||
|
||||
Return purchase using the wizard::
|
||||
|
||||
>>> Purchase = Model.get('purchase.purchase')
|
||||
>>> purchase_to_return = Purchase()
|
||||
>>> purchase_to_return.party = supplier
|
||||
>>> purchase_line = purchase_to_return.lines.new()
|
||||
>>> purchase_line.product = service
|
||||
>>> purchase_line.quantity = 1
|
||||
>>> purchase_line.unit_price = Decimal('10.0000')
|
||||
>>> purchase_line = purchase_to_return.lines.new()
|
||||
>>> purchase_line.type = 'comment'
|
||||
>>> purchase_line.description = 'Test comment'
|
||||
>>> purchase_to_return.click('quote')
|
||||
>>> purchase_to_return.click('confirm')
|
||||
>>> purchase_to_return.state
|
||||
'processing'
|
||||
>>> return_purchase = Wizard('purchase.return_purchase', [
|
||||
... purchase_to_return])
|
||||
>>> return_purchase.execute('return_')
|
||||
>>> returned_purchase, = Purchase.find([
|
||||
... ('state', '=', 'draft'),
|
||||
... ])
|
||||
>>> assertEqual(returned_purchase.origin, purchase_to_return)
|
||||
>>> sorted([x.quantity or 0 for x in returned_purchase.lines])
|
||||
[-1.0, 0]
|
||||
130
modules/purchase/tests/test_module.py
Normal file
130
modules/purchase/tests/test_module.py
Normal file
@@ -0,0 +1,130 @@
|
||||
# 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 decimal import Decimal
|
||||
|
||||
from trytond.modules.account.tests import create_chart
|
||||
from trytond.modules.company.tests import (
|
||||
CompanyTestMixin, PartyCompanyCheckEraseMixin, 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
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
class PurchaseTestCase(
|
||||
PartyCompanyCheckEraseMixin, PartyCheckReplaceMixin, CompanyTestMixin,
|
||||
ModuleTestCase):
|
||||
'Test Purchase module'
|
||||
module = 'purchase'
|
||||
|
||||
@with_transaction()
|
||||
def test_purchase_price(self):
|
||||
'Test purchase price'
|
||||
pool = Pool()
|
||||
Account = pool.get('account.account')
|
||||
Template = pool.get('product.template')
|
||||
Product = pool.get('product.product')
|
||||
Uom = pool.get('product.uom')
|
||||
ProductSupplier = pool.get('purchase.product_supplier')
|
||||
Party = pool.get('party.party')
|
||||
Purchase = pool.get('purchase.purchase')
|
||||
|
||||
company = create_company()
|
||||
with set_company(company):
|
||||
create_chart(company)
|
||||
|
||||
receivable, = Account.search([
|
||||
('closed', '!=', True),
|
||||
('type.receivable', '=', True),
|
||||
('party_required', '=', True),
|
||||
('company', '=', company.id),
|
||||
], limit=1)
|
||||
payable, = Account.search([
|
||||
('closed', '!=', True),
|
||||
('type.payable', '=', True),
|
||||
('party_required', '=', True),
|
||||
('company', '=', company.id),
|
||||
], limit=1)
|
||||
|
||||
kg, = Uom.search([('name', '=', 'Kilogram')])
|
||||
g, = Uom.search([('name', '=', 'Gram')])
|
||||
|
||||
template, = Template.create([{
|
||||
'name': 'Product',
|
||||
'default_uom': g.id,
|
||||
'purchase_uom': kg.id,
|
||||
'list_price': Decimal(5),
|
||||
'purchasable': True,
|
||||
'products': [('create', [{
|
||||
'cost_price': Decimal(3),
|
||||
}])],
|
||||
}])
|
||||
product, = template.products
|
||||
|
||||
supplier, = Party.create([{
|
||||
'name': 'Supplier',
|
||||
'account_receivable': receivable.id,
|
||||
'account_payable': payable.id,
|
||||
'addresses': [('create', [{}])],
|
||||
}])
|
||||
product_supplier, = ProductSupplier.create([{
|
||||
'template': template.id,
|
||||
'party': supplier.id,
|
||||
'prices': [('create', [{
|
||||
'sequence': 1,
|
||||
'quantity': 1,
|
||||
'unit_price': Decimal(3000),
|
||||
}, {
|
||||
'sequence': 2,
|
||||
'quantity': 2,
|
||||
'unit_price': Decimal(2500),
|
||||
}])],
|
||||
}])
|
||||
|
||||
purchase, = Purchase.create([{
|
||||
'party': supplier.id,
|
||||
'invoice_address': supplier.addresses[0].id,
|
||||
'purchase_date': dt.date.today(),
|
||||
'lines': [('create', [{
|
||||
'product': product.id,
|
||||
'quantity': 10,
|
||||
'unit': kg.id,
|
||||
'unit_price': Decimal(2000),
|
||||
}])],
|
||||
}])
|
||||
purchase.state = 'confirmed'
|
||||
purchase.save()
|
||||
|
||||
prices = Product.get_purchase_price([product], quantity=100)
|
||||
self.assertEqual(prices, {product.id: Decimal(2)})
|
||||
prices = Product.get_purchase_price([product], quantity=1500)
|
||||
self.assertEqual(prices, {product.id: Decimal(2)})
|
||||
|
||||
with Transaction().set_context(uom=kg.id):
|
||||
prices = Product.get_purchase_price([product], quantity=0.5)
|
||||
self.assertEqual(prices, {product.id: Decimal(2000)})
|
||||
prices = Product.get_purchase_price([product], quantity=1.5)
|
||||
self.assertEqual(prices, {product.id: Decimal(2000)})
|
||||
|
||||
with Transaction().set_context(supplier=supplier.id):
|
||||
prices = Product.get_purchase_price([product], quantity=100)
|
||||
self.assertEqual(prices, {product.id: Decimal(2)})
|
||||
prices = Product.get_purchase_price([product], quantity=1500)
|
||||
self.assertEqual(prices, {product.id: Decimal(3)})
|
||||
prices = Product.get_purchase_price([product], quantity=3000)
|
||||
self.assertEqual(prices, {product.id: Decimal('2.5')})
|
||||
|
||||
with Transaction().set_context(uom=kg.id, supplier=supplier.id):
|
||||
prices = Product.get_purchase_price([product], quantity=0.5)
|
||||
self.assertEqual(prices, {product.id: Decimal(2000)})
|
||||
prices = Product.get_purchase_price([product], quantity=1.5)
|
||||
self.assertEqual(prices, {product.id: Decimal(3000)})
|
||||
prices = Product.get_purchase_price([product], quantity=3)
|
||||
self.assertEqual(prices, {product.id: Decimal(2500)})
|
||||
prices = Product.get_purchase_price([product], quantity=-4)
|
||||
self.assertEqual(prices, {product.id: Decimal(2500)})
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/purchase/tests/test_scenario.py
Normal file
8
modules/purchase/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