first commit
This commit is contained in:
2
modules/product_cost_warehouse/tests/__init__.py
Normal file
2
modules/product_cost_warehouse/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,133 @@
|
||||
==================================
|
||||
Account Stock Continental 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, get_company
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
Activate product_cost_warehouse::
|
||||
|
||||
>>> config = activate_modules([
|
||||
... 'product_cost_warehouse', 'account_stock_continental'],
|
||||
... create_company, create_chart)
|
||||
|
||||
>>> Location = Model.get('stock.location')
|
||||
>>> Product = Model.get('product.product')
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> ProductConfiguration = Model.get('product.configuration')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> ShipmentInternal = Model.get('stock.shipment.internal')
|
||||
>>> StockConfiguration = Model.get('stock.configuration')
|
||||
|
||||
Get company::
|
||||
|
||||
>>> company = get_company()
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = create_fiscalyear()
|
||||
>>> fiscalyear.account_stock_method = 'continental'
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = add_stock_accounts(get_accounts())
|
||||
|
||||
Create 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.account_stock = accounts['stock']
|
||||
>>> account_category.account_stock_in = accounts['stock_expense']
|
||||
>>> account_category.account_stock_out = accounts['stock_expense']
|
||||
>>> account_category.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "Product"
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.list_price = Decimal('300')
|
||||
>>> template.cost_price_method = 'average'
|
||||
>>> template.account_category = account_category
|
||||
>>> product, = template.products
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Set cost per warehouse::
|
||||
|
||||
>>> product_config = ProductConfiguration(1)
|
||||
>>> product_config.cost_price_warehouse = True
|
||||
>>> product_config.save()
|
||||
|
||||
Create stock locations::
|
||||
|
||||
>>> warehouse1, = Location.find([('code', '=', 'WH')])
|
||||
>>> warehouse2, = warehouse1.duplicate(default={'name': "Warhouse bis"})
|
||||
>>> transit = Location(name="Transit", type='storage')
|
||||
>>> transit.save()
|
||||
>>> stock_config = StockConfiguration(1)
|
||||
>>> stock_config.shipment_internal_transit = transit
|
||||
>>> stock_config.save()
|
||||
>>> supplier_loc, = Location.find([('code', '=', 'SUP')])
|
||||
|
||||
Make 1 unit of product available @ 100 on 1st warehouse::
|
||||
|
||||
>>> StockMove = Model.get('stock.move')
|
||||
>>> move = StockMove()
|
||||
>>> move.product = product
|
||||
>>> move.quantity = 1
|
||||
>>> move.from_location = supplier_loc
|
||||
>>> move.to_location = warehouse1.storage_location
|
||||
>>> move.unit_price = Decimal('100')
|
||||
>>> move.currency = company.currency
|
||||
>>> move.click('do')
|
||||
|
||||
>>> accounts['stock'].reload()
|
||||
>>> accounts['stock'].balance
|
||||
Decimal('100.00')
|
||||
|
||||
Transfer 1 product between warehouses::
|
||||
|
||||
>>> shipment = ShipmentInternal()
|
||||
>>> shipment.from_location = warehouse1.storage_location
|
||||
>>> shipment.to_location = warehouse2.storage_location
|
||||
>>> move = shipment.moves.new()
|
||||
>>> move.from_location = shipment.from_location
|
||||
>>> move.to_location = shipment.to_location
|
||||
>>> move.product = product
|
||||
>>> move.quantity = 1
|
||||
>>> move.unit_price = product.cost_price
|
||||
>>> move.currency = company.currency
|
||||
>>> shipment.click('wait')
|
||||
>>> shipment.click('assign_force')
|
||||
|
||||
>>> shipment.click('pack')
|
||||
>>> shipment.click('ship')
|
||||
>>> shipment.state
|
||||
'shipped'
|
||||
>>> accounts['stock'].reload()
|
||||
>>> accounts['stock'].balance
|
||||
Decimal('0.00')
|
||||
|
||||
>>> shipment.click('do')
|
||||
>>> shipment.state
|
||||
'done'
|
||||
>>> accounts['stock'].reload()
|
||||
>>> accounts['stock'].balance
|
||||
Decimal('100.00')
|
||||
@@ -0,0 +1,143 @@
|
||||
====================================
|
||||
Product Cost FIFO Warehouse Scenario
|
||||
====================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> from trytond.modules.company.tests.tools import create_company, get_company
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
Activate product_cost_warehouse::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... ['product_cost_warehouse', 'product_cost_fifo'], create_company)
|
||||
|
||||
Get company::
|
||||
|
||||
>>> company = get_company()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> Product = Model.get('product.product')
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "Product"
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.list_price = Decimal('300')
|
||||
>>> template.cost_price_method = 'fifo'
|
||||
>>> product, = template.products
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Set cost per warehouse::
|
||||
|
||||
>>> ProductConfiguration = Model.get('product.configuration')
|
||||
>>> product_config = ProductConfiguration(1)
|
||||
>>> product_config.cost_price_warehouse = True
|
||||
>>> product_config.save()
|
||||
|
||||
|
||||
Create stock locations::
|
||||
|
||||
>>> Location = Model.get('stock.location')
|
||||
>>> StockConfiguration = Model.get('stock.configuration')
|
||||
>>> warehouse1, = Location.find([('code', '=', 'WH')])
|
||||
>>> warehouse2, = warehouse1.duplicate(default={'name': "Warhouse bis"})
|
||||
>>> supplier_loc, = Location.find([('code', '=', 'SUP')])
|
||||
>>> customer_loc, = Location.find([('code', '=', 'CUS')])
|
||||
|
||||
|
||||
Make 2 unit of product available @ 100 on 1st warehouse::
|
||||
|
||||
>>> StockMove = Model.get('stock.move')
|
||||
>>> move = StockMove()
|
||||
>>> move.product = product
|
||||
>>> move.quantity = 2
|
||||
>>> move.from_location = supplier_loc
|
||||
>>> move.to_location = warehouse1.storage_location
|
||||
>>> move.unit_price = Decimal('100')
|
||||
>>> move.currency = company.currency
|
||||
>>> move.click('do')
|
||||
|
||||
Check cost prices::
|
||||
|
||||
>>> with config.set_context(warehouse=warehouse1.id):
|
||||
... product = Product(product.id)
|
||||
>>> product.cost_price
|
||||
Decimal('100.0000')
|
||||
|
||||
>>> with config.set_context(warehouse=warehouse2.id):
|
||||
... product = Product(product.id)
|
||||
>>> product.cost_price
|
||||
Decimal('0')
|
||||
|
||||
Make 2 unit of product available @ 80 in both warehouses::
|
||||
|
||||
>>> moves = []
|
||||
>>> for warehouse in [warehouse1, warehouse2]:
|
||||
... move = StockMove()
|
||||
... move.product = product
|
||||
... move.quantity = 2
|
||||
... move.from_location = supplier_loc
|
||||
... move.to_location = warehouse.storage_location
|
||||
... move.unit_price = Decimal('80')
|
||||
... move.currency = company.currency
|
||||
... moves.append(move)
|
||||
>>> StockMove.click(moves, 'do')
|
||||
|
||||
Check cost prices::
|
||||
|
||||
>>> with config.set_context(warehouse=warehouse1.id):
|
||||
... product = Product(product.id)
|
||||
>>> product.cost_price
|
||||
Decimal('90.0000')
|
||||
|
||||
>>> with config.set_context(warehouse=warehouse2.id):
|
||||
... product = Product(product.id)
|
||||
>>> product.cost_price
|
||||
Decimal('80.0000')
|
||||
|
||||
Sent 3 unit of product from 1st warehouse::
|
||||
|
||||
>>> move = StockMove()
|
||||
>>> move.product = product
|
||||
>>> move.quantity = 3
|
||||
>>> move.from_location = warehouse1.storage_location
|
||||
>>> move.to_location = customer_loc
|
||||
>>> move.unit_price = Decimal('150')
|
||||
>>> move.currency = company.currency
|
||||
>>> move.click('do')
|
||||
>>> move.cost_price
|
||||
Decimal('93.3333')
|
||||
|
||||
Recompute cost price for both warehouses::
|
||||
|
||||
>>> for warehouse in [warehouse1, warehouse2]:
|
||||
... with config.set_context(warehouse=warehouse.id):
|
||||
... recompute = Wizard('product.recompute_cost_price', [product])
|
||||
... recompute.execute('recompute')
|
||||
|
||||
Check cost prices::
|
||||
|
||||
>>> with config.set_context(warehouse=warehouse1.id):
|
||||
... product = Product(product.id)
|
||||
>>> product.cost_price
|
||||
Decimal('80.0001')
|
||||
|
||||
>>> with config.set_context(warehouse=warehouse2.id):
|
||||
... product = Product(product.id)
|
||||
>>> product.cost_price
|
||||
Decimal('80.0000')
|
||||
|
||||
Check cost prices on moves::
|
||||
|
||||
>>> [m.cost_price for m in StockMove.find([])]
|
||||
[Decimal('93.3333'), Decimal('80.0000'), Decimal('90.0000'), Decimal('90.0000')]
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
===============================
|
||||
Product Cost Warehouse Scenario
|
||||
===============================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> from trytond.modules.company.tests.tools import create_company, get_company
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('product_cost_warehouse', create_company)
|
||||
|
||||
Get company::
|
||||
|
||||
>>> company = get_company()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> Product = Model.get('product.product')
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "Product"
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.list_price = Decimal('300')
|
||||
>>> template.cost_price_method = 'average'
|
||||
>>> product, = template.products
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Set cost per warehouse::
|
||||
|
||||
>>> ProductConfiguration = Model.get('product.configuration')
|
||||
>>> product_config = ProductConfiguration(1)
|
||||
>>> product_config.cost_price_warehouse = True
|
||||
>>> product_config.save()
|
||||
|
||||
|
||||
Create stock locations::
|
||||
|
||||
>>> Location = Model.get('stock.location')
|
||||
>>> StockConfiguration = Model.get('stock.configuration')
|
||||
>>> warehouse1, = Location.find([('code', '=', 'WH')])
|
||||
>>> warehouse2, = warehouse1.duplicate(default={'name': "Warhouse bis"})
|
||||
>>> transit = Location(name="Transit", type='storage')
|
||||
>>> transit.save()
|
||||
>>> stock_config = StockConfiguration(1)
|
||||
>>> stock_config.shipment_internal_transit = transit
|
||||
>>> stock_config.save()
|
||||
>>> supplier_loc, = Location.find([('code', '=', 'SUP')])
|
||||
|
||||
|
||||
Make 1 unit of product available @ 100 on 1st warehouse::
|
||||
|
||||
>>> StockMove = Model.get('stock.move')
|
||||
>>> move = StockMove()
|
||||
>>> move.product = product
|
||||
>>> move.quantity = 1
|
||||
>>> move.from_location = supplier_loc
|
||||
>>> move.to_location = warehouse1.storage_location
|
||||
>>> move.unit_price = Decimal('100')
|
||||
>>> move.currency = company.currency
|
||||
>>> move.click('do')
|
||||
|
||||
Check cost prices::
|
||||
|
||||
>>> with config.set_context(warehouse=warehouse1.id):
|
||||
... product = Product(product.id)
|
||||
>>> product.cost_price
|
||||
Decimal('100.0000')
|
||||
|
||||
>>> with config.set_context(warehouse=warehouse2.id):
|
||||
... product = Product(product.id)
|
||||
>>> product.cost_price
|
||||
Decimal('0')
|
||||
|
||||
Make 1 unit of product available @ 80 in both warehouses::
|
||||
|
||||
>>> moves = []
|
||||
>>> for warehouse in [warehouse1, warehouse2]:
|
||||
... move = StockMove()
|
||||
... move.product = product
|
||||
... move.quantity = 1
|
||||
... move.from_location = supplier_loc
|
||||
... move.to_location = warehouse.storage_location
|
||||
... move.unit_price = Decimal('80')
|
||||
... move.currency = company.currency
|
||||
... moves.append(move)
|
||||
>>> StockMove.click(moves, 'do')
|
||||
|
||||
Check cost prices::
|
||||
|
||||
>>> with config.set_context(warehouse=warehouse1.id):
|
||||
... product = Product(product.id)
|
||||
>>> product.cost_price
|
||||
Decimal('90.0000')
|
||||
|
||||
>>> with config.set_context(warehouse=warehouse2.id):
|
||||
... product = Product(product.id)
|
||||
>>> product.cost_price
|
||||
Decimal('80.0000')
|
||||
|
||||
Recompute cost price for both warehouses::
|
||||
|
||||
>>> for warehouse in [warehouse1, warehouse2]:
|
||||
... with config.set_context(warehouse=warehouse.id):
|
||||
... recompute = Wizard('product.recompute_cost_price', [product])
|
||||
... recompute.execute('recompute')
|
||||
|
||||
Check cost prices::
|
||||
|
||||
>>> with config.set_context(warehouse=warehouse1.id):
|
||||
... product = Product(product.id)
|
||||
>>> product.cost_price
|
||||
Decimal('90.0000')
|
||||
|
||||
>>> with config.set_context(warehouse=warehouse2.id):
|
||||
... product = Product(product.id)
|
||||
>>> product.cost_price
|
||||
Decimal('80.0000')
|
||||
|
||||
Check cost prices on moves::
|
||||
|
||||
>>> [m.cost_price for m in StockMove.find([])]
|
||||
[Decimal('80.0000'), Decimal('90.0000'), Decimal('90.0000')]
|
||||
|
||||
Forbid direct move between warehouses::
|
||||
|
||||
>>> move = StockMove()
|
||||
>>> move.product = product
|
||||
>>> move.quantity = 1
|
||||
>>> move.from_location = warehouse1.storage_location
|
||||
>>> move.to_location = warehouse2.storage_location
|
||||
>>> move.unit_price = product.cost_price
|
||||
>>> move.currency = company.currency
|
||||
>>> move.save()
|
||||
>>> move.click('do')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
MoveValidationError: ...
|
||||
|
||||
>>> move.to_location = transit
|
||||
>>> move.click('do')
|
||||
>>> move.state
|
||||
'done'
|
||||
|
||||
Transfer 1 product between warehouses::
|
||||
|
||||
>>> ShipmentInternal = Model.get('stock.shipment.internal')
|
||||
>>> shipment = ShipmentInternal()
|
||||
>>> shipment.from_location = warehouse1.storage_location
|
||||
>>> shipment.to_location = warehouse2.storage_location
|
||||
>>> move = shipment.moves.new()
|
||||
>>> move.from_location = shipment.from_location
|
||||
>>> move.to_location = shipment.to_location
|
||||
>>> move.product = product
|
||||
>>> move.quantity = 1
|
||||
>>> move.unit_price = product.cost_price
|
||||
>>> move.currency = company.currency
|
||||
>>> shipment.click('wait')
|
||||
>>> shipment.state
|
||||
'waiting'
|
||||
>>> shipment.click('assign_force')
|
||||
>>> shipment.state
|
||||
'assigned'
|
||||
|
||||
>>> shipment.click('pack')
|
||||
>>> shipment.click('ship')
|
||||
>>> shipment.state
|
||||
'shipped'
|
||||
>>> move, = shipment.outgoing_moves
|
||||
>>> move.state
|
||||
'done'
|
||||
>>> move.cost_price
|
||||
Decimal('90.0000')
|
||||
|
||||
>>> shipment.click('do')
|
||||
>>> shipment.state
|
||||
'done'
|
||||
>>> move, = shipment.incoming_moves
|
||||
>>> move.state
|
||||
'done'
|
||||
>>> move.cost_price
|
||||
Decimal('85.0000')
|
||||
|
||||
Recompute cost price for both warehouses::
|
||||
|
||||
>>> for warehouse in [warehouse1, warehouse2]:
|
||||
... with config.set_context(warehouse=warehouse.id):
|
||||
... recompute = Wizard('product.recompute_cost_price', [product])
|
||||
... recompute.execute('recompute')
|
||||
|
||||
Check cost prices::
|
||||
|
||||
>>> with config.set_context(warehouse=warehouse1.id):
|
||||
... product = Product(product.id)
|
||||
>>> product.cost_price
|
||||
Decimal('90.0000')
|
||||
|
||||
>>> with config.set_context(warehouse=warehouse2.id):
|
||||
... product = Product(product.id)
|
||||
>>> product.cost_price
|
||||
Decimal('85.0000')
|
||||
14
modules/product_cost_warehouse/tests/test_module.py
Normal file
14
modules/product_cost_warehouse/tests/test_module.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# 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.modules.company.tests import CompanyTestMixin
|
||||
from trytond.tests.test_tryton import ModuleTestCase
|
||||
|
||||
|
||||
class ProductCostWarehouseTestCase(CompanyTestMixin, ModuleTestCase):
|
||||
'Test Product Cost Warehouse module'
|
||||
module = 'product_cost_warehouse'
|
||||
extras = ['account_invoice_stock', 'product_cost_history']
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/product_cost_warehouse/tests/test_scenario.py
Normal file
8
modules/product_cost_warehouse/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