first commit
This commit is contained in:
2
modules/account_stock_continental/tests/__init__.py
Normal file
2
modules/account_stock_continental/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.
Binary file not shown.
@@ -0,0 +1,392 @@
|
||||
==================================
|
||||
Account Stock Continental Scenario
|
||||
==================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> 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.account_stock_continental.tests.tools import (
|
||||
... add_stock_accounts)
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules([
|
||||
... 'account_stock_continental',
|
||||
... 'sale',
|
||||
... 'purchase',
|
||||
... 'sale_supply_drop_shipment',
|
||||
... ],
|
||||
... create_company, create_chart)
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
||||
... create_fiscalyear(today=today))
|
||||
>>> fiscalyear.account_stock_method = 'continental'
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = add_stock_accounts(get_accounts())
|
||||
>>> receivable = accounts['receivable']
|
||||
>>> payable = accounts['payable']
|
||||
>>> revenue = accounts['revenue']
|
||||
>>> expense = accounts['expense']
|
||||
>>> stock = accounts['stock']
|
||||
>>> stock_in = accounts['stock_expense']
|
||||
>>> stock_out, = stock_in.duplicate()
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.save()
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.save()
|
||||
|
||||
Create product 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.account_stock = stock
|
||||
>>> account_category.account_stock_in = stock_in
|
||||
>>> account_category.account_stock_out = stock_out
|
||||
>>> account_category.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> m, = ProductUom.find([('symbol', '=', 'm')])
|
||||
>>> cm, = ProductUom.find([('symbol', '=', 'cm')])
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'product'
|
||||
>>> template.default_uom = cm
|
||||
>>> template.type = 'goods'
|
||||
>>> template.purchasable = True
|
||||
>>> template.salable = True
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.cost_price_method = 'fixed'
|
||||
>>> template.lead_time = dt.timedelta(0)
|
||||
>>> template.account_category = account_category
|
||||
>>> product, = template.products
|
||||
>>> product.cost_price = Decimal('5')
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
>>> template_average, = template.duplicate({
|
||||
... 'cost_price_method': 'average',
|
||||
... })
|
||||
>>> template_average.account_category = account_category
|
||||
>>> template_average.save()
|
||||
>>> product_average, = template_average.products
|
||||
|
||||
Create payment term::
|
||||
|
||||
>>> payment_term = create_payment_term()
|
||||
>>> payment_term.save()
|
||||
|
||||
Purchase 12 products::
|
||||
|
||||
>>> Purchase = Model.get('purchase.purchase')
|
||||
>>> purchase = Purchase()
|
||||
>>> purchase.party = supplier
|
||||
>>> purchase.payment_term = payment_term
|
||||
>>> purchase.invoice_method = 'shipment'
|
||||
>>> purchase_line = purchase.lines.new()
|
||||
>>> purchase_line.product = product
|
||||
>>> purchase_line.quantity = 5.0
|
||||
>>> purchase_line.unit = m
|
||||
>>> purchase_line.unit_price = Decimal(400)
|
||||
>>> purchase_line = purchase.lines.new()
|
||||
>>> purchase_line.product = product_average
|
||||
>>> purchase_line.quantity = 7.0
|
||||
>>> purchase_line.unit = m
|
||||
>>> purchase_line.unit_price = Decimal(600)
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.click('confirm')
|
||||
>>> purchase.click('process')
|
||||
>>> purchase.state
|
||||
'processing'
|
||||
|
||||
Receive 9 products::
|
||||
|
||||
>>> ShipmentIn = Model.get('stock.shipment.in')
|
||||
>>> Move = Model.get('stock.move')
|
||||
>>> shipment = ShipmentIn(supplier=supplier)
|
||||
>>> move, = [m for m in purchase.moves if m.product == product]
|
||||
>>> move = Move(move.id)
|
||||
>>> shipment.incoming_moves.append(move)
|
||||
>>> move.quantity = 4.0
|
||||
>>> move, = [m for m in purchase.moves if m.product == product_average]
|
||||
>>> move = Move(move.id)
|
||||
>>> shipment.incoming_moves.append(move)
|
||||
>>> move.quantity = 5.0
|
||||
>>> shipment.click('receive')
|
||||
>>> shipment.click('do')
|
||||
>>> shipment.state
|
||||
'done'
|
||||
>>> stock_in.reload()
|
||||
>>> stock_in.debit
|
||||
Decimal('0.00')
|
||||
>>> stock_in.credit
|
||||
Decimal('5000.00')
|
||||
>>> stock.reload()
|
||||
>>> stock.debit
|
||||
Decimal('5000.00')
|
||||
>>> stock.credit
|
||||
Decimal('0.00')
|
||||
|
||||
Open supplier invoice::
|
||||
|
||||
>>> Invoice = Model.get('account.invoice')
|
||||
>>> purchase.reload()
|
||||
>>> invoice, = purchase.invoices
|
||||
>>> invoice_line, = [l for l in invoice.lines if l.product == product]
|
||||
>>> invoice_line.unit_price = Decimal('6')
|
||||
>>> invoice_line, = [l for l in invoice.lines
|
||||
... if l.product == product_average]
|
||||
>>> invoice_line.unit_price = Decimal('4')
|
||||
>>> invoice.invoice_date = today
|
||||
>>> invoice.click('post')
|
||||
>>> invoice.state
|
||||
'posted'
|
||||
>>> payable.reload()
|
||||
>>> payable.debit
|
||||
Decimal('0.00')
|
||||
>>> payable.credit
|
||||
Decimal('44.00')
|
||||
>>> expense.reload()
|
||||
>>> expense.debit
|
||||
Decimal('44.00')
|
||||
>>> expense.credit
|
||||
Decimal('0.00')
|
||||
|
||||
Sale 5 products::
|
||||
|
||||
>>> Sale = Model.get('sale.sale')
|
||||
>>> sale = Sale()
|
||||
>>> sale.party = customer
|
||||
>>> sale.payment_term = payment_term
|
||||
>>> sale.invoice_method = 'shipment'
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product
|
||||
>>> sale_line.quantity = 2.0
|
||||
>>> sale_line.unit = cm
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product_average
|
||||
>>> sale_line.quantity = 3.0
|
||||
>>> sale_line.unit = cm
|
||||
>>> sale.click('quote')
|
||||
>>> sale.click('confirm')
|
||||
>>> sale.click('process')
|
||||
>>> sale.state
|
||||
'processing'
|
||||
|
||||
Send 5 products::
|
||||
|
||||
>>> shipment, = sale.shipments
|
||||
>>> shipment.click('assign_try')
|
||||
>>> shipment.state
|
||||
'assigned'
|
||||
>>> shipment.click('pick')
|
||||
>>> shipment.state
|
||||
'picked'
|
||||
>>> shipment.click('pack')
|
||||
>>> shipment.state
|
||||
'packed'
|
||||
>>> shipment.click('do')
|
||||
>>> shipment.state
|
||||
'done'
|
||||
>>> stock_out.reload()
|
||||
>>> stock_out.debit
|
||||
Decimal('28.00')
|
||||
>>> stock_out.credit
|
||||
Decimal('0.00')
|
||||
>>> stock.reload()
|
||||
>>> stock.debit
|
||||
Decimal('5000.00')
|
||||
>>> stock.credit
|
||||
Decimal('28.00')
|
||||
|
||||
Open customer invoice::
|
||||
|
||||
>>> sale.reload()
|
||||
>>> invoice, = sale.invoices
|
||||
>>> invoice.click('post')
|
||||
>>> invoice.state
|
||||
'posted'
|
||||
>>> receivable.reload()
|
||||
>>> receivable.debit
|
||||
Decimal('50.00')
|
||||
>>> receivable.credit
|
||||
Decimal('0.00')
|
||||
>>> revenue.reload()
|
||||
>>> revenue.debit
|
||||
Decimal('0.00')
|
||||
>>> revenue.credit
|
||||
Decimal('50.00')
|
||||
|
||||
Create an Inventory::
|
||||
|
||||
>>> Inventory = Model.get('stock.inventory')
|
||||
>>> Location = Model.get('stock.location')
|
||||
>>> storage, = Location.find([
|
||||
... ('code', '=', 'STO'),
|
||||
... ])
|
||||
>>> inventory = Inventory()
|
||||
>>> inventory.location = storage
|
||||
>>> inventory.click('complete_lines')
|
||||
>>> inventory_line, = [l for l in inventory.lines if l.product == product]
|
||||
>>> inventory_line.quantity = 100.0
|
||||
>>> inventory_line, = [l for l in inventory.lines
|
||||
... if l.product == product_average]
|
||||
>>> inventory_line.quantity = 100.0
|
||||
>>> inventory.click('confirm')
|
||||
>>> inventory.state
|
||||
'done'
|
||||
>>> stock_out.reload()
|
||||
>>> stock_out.debit
|
||||
Decimal('3900.00')
|
||||
>>> stock_out.credit
|
||||
Decimal('0.00')
|
||||
>>> stock.reload()
|
||||
>>> stock.debit
|
||||
Decimal('5000.00')
|
||||
>>> stock.credit
|
||||
Decimal('3900.00')
|
||||
|
||||
Create Drop Shipment Move::
|
||||
|
||||
>>> ProductSupplier = Model.get('purchase.product_supplier')
|
||||
>>> product_supplier = ProductSupplier()
|
||||
>>> product_supplier.template = product.template
|
||||
>>> product_supplier.party = supplier
|
||||
>>> product_supplier.drop_shipment = True
|
||||
>>> product_supplier.lead_time = dt.timedelta(0)
|
||||
>>> product_supplier.save()
|
||||
>>> product.template.supply_on_sale = 'always'
|
||||
>>> product.template.save()
|
||||
|
||||
>>> sale = Sale()
|
||||
>>> sale.party = customer
|
||||
>>> sale.payment_term = payment_term
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product
|
||||
>>> sale_line.quantity = 300
|
||||
>>> sale_line.unit = cm
|
||||
>>> sale.click('quote')
|
||||
>>> sale.click('confirm')
|
||||
>>> sale.click('process')
|
||||
>>> sale.state
|
||||
'processing'
|
||||
|
||||
>>> PurchaseRequest = Model.get('purchase.request')
|
||||
>>> purchase_request, = PurchaseRequest.find()
|
||||
>>> create_purchase = Wizard('purchase.request.create_purchase',
|
||||
... [purchase_request])
|
||||
>>> purchase = purchase_request.purchase
|
||||
>>> purchase.payment_term = payment_term
|
||||
>>> purchase_line, = purchase.lines
|
||||
>>> purchase_line.unit_price = Decimal(6)
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.click('confirm')
|
||||
>>> purchase.click('process')
|
||||
>>> purchase.state
|
||||
'processing'
|
||||
|
||||
>>> shipment, = sale.drop_shipments
|
||||
>>> shipment.click('ship')
|
||||
>>> shipment.click('do')
|
||||
>>> shipment.state
|
||||
'done'
|
||||
|
||||
>>> stock_in.reload()
|
||||
>>> stock_in.debit
|
||||
Decimal('0.00')
|
||||
>>> stock_in.credit
|
||||
Decimal('6800.00')
|
||||
>>> stock_out.reload()
|
||||
>>> stock_out.debit
|
||||
Decimal('5700.00')
|
||||
>>> stock_out.credit
|
||||
Decimal('0.00')
|
||||
|
||||
>>> product_supplier = ProductSupplier()
|
||||
>>> product_supplier.template = product_average.template
|
||||
>>> product_supplier.party = supplier
|
||||
>>> product_supplier.drop_shipment = True
|
||||
>>> product_supplier.lead_time = dt.timedelta(0)
|
||||
>>> product_supplier.save()
|
||||
>>> product_average.template.supply_on_sale = 'always'
|
||||
>>> product_average.template.save()
|
||||
|
||||
>>> sale = Sale()
|
||||
>>> sale.party = customer
|
||||
>>> sale.payment_term = payment_term
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product_average
|
||||
>>> sale_line.quantity = 400
|
||||
>>> sale.click('quote')
|
||||
>>> sale.click('confirm')
|
||||
>>> sale.click('process')
|
||||
>>> sale.state
|
||||
'processing'
|
||||
|
||||
>>> purchase_request, = [p for p in PurchaseRequest.find()
|
||||
... if p.state == 'draft']
|
||||
>>> create_purchase = Wizard('purchase.request.create_purchase',
|
||||
... [purchase_request])
|
||||
>>> purchase = purchase_request.purchase
|
||||
>>> purchase.payment_term = payment_term
|
||||
>>> purchase_line, = purchase.lines
|
||||
>>> purchase_line.unit_price = Decimal(5)
|
||||
>>> purchase.click('quote')
|
||||
>>> purchase.click('confirm')
|
||||
>>> purchase.click('process')
|
||||
>>> purchase.state
|
||||
'processing'
|
||||
|
||||
>>> shipment, = sale.drop_shipments
|
||||
>>> shipment.click('ship')
|
||||
>>> shipment.click('do')
|
||||
>>> shipment.state
|
||||
'done'
|
||||
|
||||
>>> stock_in.reload()
|
||||
>>> stock_in.debit
|
||||
Decimal('0.00')
|
||||
>>> stock_in.credit
|
||||
Decimal('8800.00')
|
||||
>>> stock_out.reload()
|
||||
>>> stock_out.debit
|
||||
Decimal('7700.00')
|
||||
>>> stock_out.credit
|
||||
Decimal('0.00')
|
||||
|
||||
Modify cost price::
|
||||
|
||||
>>> Account = Model.get('account.account')
|
||||
>>> modify_price = Wizard('product.modify_cost_price', [product])
|
||||
>>> modify_price.form.cost_price = '3.00'
|
||||
>>> modify_price.execute('modify')
|
||||
>>> product.cost_price
|
||||
Decimal('3.0000')
|
||||
>>> stock_out.reload()
|
||||
>>> stock_out.debit
|
||||
Decimal('7900.00')
|
||||
>>> stock_out.credit
|
||||
Decimal('0.00')
|
||||
@@ -0,0 +1,104 @@
|
||||
=================================================
|
||||
Account Stock Continental Move Cancelled 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_stock_continental.tests.tools import (
|
||||
... add_stock_accounts)
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.modules.currency.tests.tools import get_currency
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... 'account_stock_continental', create_company, create_chart)
|
||||
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> StockMove = Model.get('stock.move')
|
||||
>>> StockLocation = Model.get('stock.location')
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = create_fiscalyear()
|
||||
>>> fiscalyear.account_stock_method = 'continental'
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = add_stock_accounts(get_accounts())
|
||||
>>> receivable = accounts['receivable']
|
||||
>>> payable = accounts['payable']
|
||||
>>> revenue = accounts['revenue']
|
||||
>>> expense = accounts['expense']
|
||||
>>> stock = accounts['stock']
|
||||
>>> stock_in = accounts['stock_expense']
|
||||
>>> stock_out, = stock_in.duplicate()
|
||||
|
||||
Get stock locations::
|
||||
|
||||
>>> supplier_loc, = StockLocation.find([('code', '=', 'SUP')])
|
||||
>>> storage_loc, = StockLocation.find([('code', '=', 'STO')])
|
||||
|
||||
Create product category::
|
||||
|
||||
>>> account_category = ProductCategory(name="Account Category")
|
||||
>>> account_category.accounting = True
|
||||
>>> account_category.account_expense = expense
|
||||
>>> account_category.account_revenue = revenue
|
||||
>>> account_category.account_stock = stock
|
||||
>>> account_category.account_stock_in = stock_in
|
||||
>>> account_category.account_stock_out = stock_out
|
||||
>>> account_category.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "Product"
|
||||
>>> template.default_uom, = ProductUom.find([('name', '=', "Unit")])
|
||||
>>> template.type = 'goods'
|
||||
>>> template.cost_price_method = 'fixed'
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
>>> product.cost_price = Decimal('10.0000')
|
||||
>>> product.save()
|
||||
|
||||
Receive product::
|
||||
|
||||
>>> stock_move = StockMove()
|
||||
>>> stock_move.product = product
|
||||
>>> stock_move.from_location = supplier_loc
|
||||
>>> stock_move.to_location = storage_loc
|
||||
>>> stock_move.quantity = 1
|
||||
>>> stock_move.unit_price = Decimal('10.0000')
|
||||
>>> stock_move.currency = get_currency()
|
||||
>>> stock_move.click('do')
|
||||
>>> stock_move.state
|
||||
'done'
|
||||
>>> account_move, = stock_move.account_moves
|
||||
>>> account_move.state
|
||||
'posted'
|
||||
>>> stock.reload()
|
||||
>>> stock.balance
|
||||
Decimal('10.00')
|
||||
|
||||
Cancel reception::
|
||||
|
||||
>>> stock_move.click('cancel')
|
||||
>>> stock_move.state
|
||||
'cancelled'
|
||||
>>> len(stock_move.account_moves)
|
||||
2
|
||||
>>> assertEqual([m.state for m in stock_move.account_moves], ['posted', 'posted'])
|
||||
>>> stock.reload()
|
||||
>>> stock.balance
|
||||
Decimal('0.00')
|
||||
12
modules/account_stock_continental/tests/test_module.py
Normal file
12
modules/account_stock_continental/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 AccountStockContinentalTestCase(ModuleTestCase):
|
||||
'Test Account Stock Continental module'
|
||||
module = 'account_stock_continental'
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/account_stock_continental/tests/test_scenario.py
Normal file
8
modules/account_stock_continental/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)
|
||||
22
modules/account_stock_continental/tests/tools.py
Normal file
22
modules/account_stock_continental/tests/tools.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# 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 proteus import Model
|
||||
from trytond.modules.company.tests.tools import get_company
|
||||
|
||||
|
||||
def add_stock_accounts(accounts, company=None, config=None):
|
||||
"Add stock kind to accounts"
|
||||
Account = Model.get('account.account', config=config)
|
||||
|
||||
if not company:
|
||||
company = get_company(config=config)
|
||||
|
||||
accounts['stock'], = Account.find([
|
||||
('company', '=', company.id),
|
||||
('code', '=', '1.3.1'),
|
||||
])
|
||||
accounts['stock_expense'], = Account.find([
|
||||
('company', '=', company.id),
|
||||
('code', '=', '5.1.5'),
|
||||
])
|
||||
return accounts
|
||||
Reference in New Issue
Block a user