first commit
This commit is contained in:
2
modules/stock_supply_forecast/__init__.py
Normal file
2
modules/stock_supply_forecast/__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.
BIN
modules/stock_supply_forecast/__pycache__/stock.cpython-311.pyc
Normal file
BIN
modules/stock_supply_forecast/__pycache__/stock.cpython-311.pyc
Normal file
Binary file not shown.
23
modules/stock_supply_forecast/stock.py
Normal file
23
modules/stock_supply_forecast/stock.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# 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.pool import Pool, PoolMeta
|
||||
|
||||
|
||||
class Supply(metaclass=PoolMeta):
|
||||
__name__ = 'stock.supply'
|
||||
|
||||
def transition_create_(self):
|
||||
pool = Pool()
|
||||
Forecast = pool.get('stock.forecast')
|
||||
Date = pool.get('ir.date')
|
||||
|
||||
today = Date.today()
|
||||
|
||||
forecasts = Forecast.search([
|
||||
('to_date', '>=', today),
|
||||
('state', '=', 'done'),
|
||||
])
|
||||
Forecast.create_moves(forecasts)
|
||||
transition = super().transition_create_()
|
||||
Forecast.delete_moves(forecasts)
|
||||
return transition
|
||||
2
modules/stock_supply_forecast/tests/__init__.py
Normal file
2
modules/stock_supply_forecast/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,94 @@
|
||||
==============================
|
||||
Stock Supply Forecast Scenario
|
||||
==============================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> from trytond.modules.account.tests.tools import create_chart, get_accounts
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
>>> today = dt.date.today()
|
||||
>>> yesterday = today - dt.timedelta(days=1)
|
||||
>>> tomorrow = today + dt.timedelta(days=1)
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... 'stock_supply_forecast', create_company, create_chart)
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> expense = accounts['expense']
|
||||
|
||||
Create parties::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.save()
|
||||
>>> supplier = Party(name='Supplier')
|
||||
>>> supplier.save()
|
||||
|
||||
Create account category::
|
||||
|
||||
>>> 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')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'Product'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.list_price = Decimal('20')
|
||||
>>> template.purchasable = True
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Get warehouse location::
|
||||
|
||||
>>> Location = Model.get('stock.location')
|
||||
>>> warehouse_loc, = Location.find([('code', '=', 'WH')])
|
||||
|
||||
Create a forecast::
|
||||
|
||||
>>> Forecast = Model.get('stock.forecast')
|
||||
>>> forecast = Forecast()
|
||||
>>> forecast.warehouse = warehouse_loc
|
||||
>>> forecast.from_date = yesterday
|
||||
>>> forecast.to_date = tomorrow
|
||||
>>> forecast_line = forecast.lines.new()
|
||||
>>> forecast_line.product = product
|
||||
>>> forecast_line.quantity = 10
|
||||
>>> forecast.save()
|
||||
|
||||
There is no purchase request::
|
||||
|
||||
>>> create_pr = Wizard('stock.supply')
|
||||
>>> create_pr.execute('create_')
|
||||
>>> PurchaseRequest = Model.get('purchase.request')
|
||||
>>> PurchaseRequest.find([])
|
||||
[]
|
||||
|
||||
There is a draft purchase request after confirming the forecast::
|
||||
|
||||
>>> forecast.click('confirm')
|
||||
>>> create_pr = Wizard('stock.supply')
|
||||
>>> create_pr.execute('create_')
|
||||
>>> pr, = PurchaseRequest.find([('state', '=', 'draft')])
|
||||
>>> assertEqual(pr.product, product)
|
||||
>>> pr.quantity
|
||||
10.0
|
||||
12
modules/stock_supply_forecast/tests/test_module.py
Normal file
12
modules/stock_supply_forecast/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 StockSupplyForecastTestCase(ModuleTestCase):
|
||||
'Test StockSupplyForecast module'
|
||||
module = 'stock_supply_forecast'
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/stock_supply_forecast/tests/test_scenario.py
Normal file
8
modules/stock_supply_forecast/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)
|
||||
10
modules/stock_supply_forecast/tryton.cfg
Normal file
10
modules/stock_supply_forecast/tryton.cfg
Normal file
@@ -0,0 +1,10 @@
|
||||
[tryton]
|
||||
version=7.8.0
|
||||
depends:
|
||||
ir
|
||||
stock_supply
|
||||
stock_forecast
|
||||
|
||||
[register]
|
||||
wizard:
|
||||
stock.Supply
|
||||
Reference in New Issue
Block a user