first commit

This commit is contained in:
root
2026-03-14 09:42:12 +00:00
commit 0adbd20c2c
10991 changed files with 1646955 additions and 0 deletions

View 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.

View File

@@ -0,0 +1,154 @@
=====================
Stock FIFO Cost Price
=====================
Imports::
>>> import datetime as dt
>>> from decimal import Decimal
>>> from proteus import Model
>>> from trytond.modules.company.tests.tools import create_company, get_company
>>> from trytond.tests.tools import activate_modules
>>> today = dt.date.today()
Activate modules::
>>> config = activate_modules('product_cost_fifo', create_company)
Get company::
>>> company = get_company()
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('300')
>>> template.cost_price_method = 'fifo'
>>> product, = template.products
>>> product.cost_price = Decimal('80')
>>> template.save()
>>> product, = template.products
Get stock locations::
>>> Location = Model.get('stock.location')
>>> supplier_loc, = Location.find([('code', '=', 'SUP')])
>>> customer_loc, = Location.find([('code', '=', 'CUS')])
>>> storage_loc, = Location.find([('code', '=', 'STO')])
>>> production_loc = Location(name="Production", type='production')
>>> production_loc.save()
Make 4 units of the product available @ 10 ::
>>> StockMove = Model.get('stock.move')
>>> incoming_move = StockMove()
>>> incoming_move.product = product
>>> incoming_move.unit = unit
>>> incoming_move.quantity = 4
>>> incoming_move.from_location = supplier_loc
>>> incoming_move.to_location = storage_loc
>>> incoming_move.planned_date = today
>>> incoming_move.company = company
>>> incoming_move.unit_price = Decimal('10')
>>> incoming_move.currency = company.currency
>>> incoming_move.click('do')
Check Cost Price is 10::
>>> product.reload()
>>> product.cost_price
Decimal('10.0000')
Add 2 more units @ 25 from production::
>>> incoming_move = StockMove()
>>> incoming_move.product = product
>>> incoming_move.unit = unit
>>> incoming_move.quantity = 2
>>> incoming_move.from_location = production_loc
>>> incoming_move.to_location = storage_loc
>>> incoming_move.planned_date = today
>>> incoming_move.company = company
>>> incoming_move.unit_price = Decimal('25')
>>> incoming_move.currency = company.currency
>>> incoming_move.click('do')
Check Cost Price FIFO is 15::
>>> product.reload()
>>> product.cost_price
Decimal('15.0000')
Sell 3 units @ 50::
>>> outgoing_move = StockMove()
>>> outgoing_move.product = product
>>> outgoing_move.unit = unit
>>> outgoing_move.quantity = 3
>>> outgoing_move.from_location = storage_loc
>>> outgoing_move.to_location = customer_loc
>>> outgoing_move.planned_date = today
>>> outgoing_move.company = company
>>> outgoing_move.unit_price = Decimal('50')
>>> outgoing_move.currency = company.currency
>>> outgoing_move.click('do')
Check Cost Price FIFO is 20 and cost is 10::
>>> product.reload()
>>> product.cost_price
Decimal('20.0000')
>>> outgoing_move.cost_price
Decimal('10.0000')
>>> outgoing_move.product_cost_price
Decimal('20.0000')
Sell twice 1 more units @ 50::
>>> outgoing_moves = []
>>> outgoing_move = StockMove()
>>> outgoing_move.product = product
>>> outgoing_move.unit = unit
>>> outgoing_move.quantity = 1
>>> outgoing_move.from_location = storage_loc
>>> outgoing_move.to_location = customer_loc
>>> outgoing_move.planned_date = today
>>> outgoing_move.company = company
>>> outgoing_move.unit_price = Decimal('50')
>>> outgoing_move.currency = company.currency
>>> outgoing_move.save()
>>> outgoing_moves.append(outgoing_move)
>>> outgoing_move = StockMove()
>>> outgoing_move.product = product
>>> outgoing_move.unit = unit
>>> outgoing_move.quantity = 1
>>> outgoing_move.from_location = storage_loc
>>> outgoing_move.to_location = customer_loc
>>> outgoing_move.planned_date = today
>>> outgoing_move.company = company
>>> outgoing_move.unit_price = Decimal('50')
>>> outgoing_move.currency = company.currency
>>> outgoing_move.save()
>>> outgoing_moves.append(outgoing_move)
>>> StockMove.click(outgoing_moves, 'do')
Check Cost Price FIFO is 25 and costs are 10 and 25::
>>> product.reload()
>>> product.cost_price
Decimal('25.0000')
>>> [m.cost_price for m in outgoing_moves]
[Decimal('10.0000'), Decimal('25.0000')]
>>> [m.product_cost_price for m in outgoing_moves]
[Decimal('25.0000'), Decimal('25.0000')]

View File

@@ -0,0 +1,100 @@
===================================
Stock FIFO Cost Price with no Input
===================================
Imports::
>>> import datetime as dt
>>> from decimal import Decimal
>>> from proteus import Model
>>> from trytond.modules.company.tests.tools import create_company, get_company
>>> from trytond.tests.tools import activate_modules
>>> today = dt.date.today()
Activate modules::
>>> config = activate_modules('product_cost_fifo', create_company)
Get company::
>>> company = get_company()
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('300')
>>> template.cost_price_method = 'fifo'
>>> product, = template.products
>>> product.cost_price = Decimal('80')
>>> template.save()
>>> product, = template.products
Get stock locations::
>>> Location = Model.get('stock.location')
>>> supplier_loc, = Location.find([('code', '=', 'SUP')])
>>> customer_loc, = Location.find([('code', '=', 'CUS')])
>>> storage_loc, = Location.find([('code', '=', 'STO')])
Make 2 units of the product not available @ 60 and 80 ::
>>> StockMove = Model.get('stock.move')
>>> incoming_move = StockMove()
>>> incoming_move.product = product
>>> incoming_move.unit = unit
>>> incoming_move.quantity = 1
>>> incoming_move.from_location = supplier_loc
>>> incoming_move.to_location = storage_loc
>>> incoming_move.planned_date = today
>>> incoming_move.company = company
>>> incoming_move.unit_price = Decimal('60')
>>> incoming_move.currency = company.currency
>>> incoming_move.fifo_quantity = 1
>>> incoming_move.click('do')
>>> incoming_move = StockMove()
>>> incoming_move.product = product
>>> incoming_move.unit = unit
>>> incoming_move.quantity = 1
>>> incoming_move.from_location = supplier_loc
>>> incoming_move.to_location = storage_loc
>>> incoming_move.planned_date = today
>>> incoming_move.company = company
>>> incoming_move.unit_price = Decimal('80')
>>> incoming_move.currency = company.currency
>>> incoming_move.fifo_quantity = 1
>>> incoming_move.click('do')
Sell 1 unit @ 200::
>>> StockMove = Model.get('stock.move')
>>> outgoing_move = StockMove()
>>> outgoing_move.product = product
>>> outgoing_move.unit = unit
>>> outgoing_move.quantity = 1
>>> outgoing_move.from_location = storage_loc
>>> outgoing_move.to_location = customer_loc
>>> outgoing_move.planned_date = today
>>> outgoing_move.company = company
>>> outgoing_move.unit_price = Decimal('200')
>>> outgoing_move.currency = company.currency
>>> outgoing_move.click('do')
Check Cost Price FIFO is the current cost price::
>>> product.reload()
>>> product.cost_price
Decimal('70.0000')
>>> outgoing_move.cost_price
Decimal('70.0000')
>>> outgoing_move.product_cost_price
Decimal('70.0000')

View File

@@ -0,0 +1,142 @@
======================================
Product Cost FIFO Recompute Cost Price
======================================
Imports::
>>> import datetime as dt
>>> 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
>>> today = dt.date.today()
Activate modules::
>>> config = activate_modules('product_cost_fifo', create_company)
Get company::
>>> company = get_company()
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('300')
>>> template.cost_price_method = 'fifo'
>>> product, = template.products
>>> product.cost_price = Decimal('80')
>>> template.save()
>>> product, = template.products
Get stock locations::
>>> Location = Model.get('stock.location')
>>> supplier_loc, = Location.find([('code', '=', 'SUP')])
>>> storage_loc, = Location.find([('code', '=', 'STO')])
>>> customer_loc, = Location.find([('code', '=', 'CUS')])
>>> lost_found, = Location.find([('name', '=', "Lost and Found")])
Create some moves::
>>> StockMove = Model.get('stock.move')
>>> StockMove(
... product=product,
... quantity=1,
... from_location=supplier_loc,
... to_location=storage_loc,
... unit_price=Decimal('100'),
... currency=company.currency,
... effective_date=today - dt.timedelta(days=2)).click('do')
>>> StockMove(
... product=product,
... quantity=2,
... from_location=supplier_loc,
... to_location=storage_loc,
... unit_price=Decimal('120'),
... currency=company.currency,
... effective_date=today - dt.timedelta(days=1)).click('do')
>>> StockMove(
... product=product,
... quantity=1,
... from_location=lost_found,
... to_location=storage_loc,
... effective_date=today - dt.timedelta(days=1)).click('do')
>>> StockMove(
... product=product,
... quantity=2,
... from_location=storage_loc,
... to_location=customer_loc,
... unit_price=Decimal('300'),
... currency=company.currency,
... effective_date=today - dt.timedelta(days=1)).click('do')
>>> StockMove(
... product=product,
... quantity=3,
... from_location=supplier_loc,
... to_location=storage_loc,
... unit_price=Decimal('100'),
... currency=company.currency,
... effective_date=today).click('do')
>>> StockMove(
... product=product,
... quantity=2,
... from_location=storage_loc,
... to_location=customer_loc,
... unit_price=Decimal('300'),
... currency=company.currency,
... effective_date=today).click('do')
>>> StockMove(
... product=product,
... quantity=1,
... from_location=storage_loc,
... to_location=lost_found,
... effective_date=today).click('do')
>>> [m.cost_price for m in StockMove.find([])]
[Decimal('100.0000'), Decimal('116.6666'), Decimal('106.6666'), Decimal('110.0000'), Decimal('113.3333'), Decimal('113.3333'), Decimal('100.0000')]
>>> [m.product_cost_price for m in StockMove.find([])]
[Decimal('99.9998'), Decimal('99.9999'), None, Decimal('116.6666'), None, None, None]
>>> product.reload()
>>> product.cost_price
Decimal('99.9998')
Recompute cost price::
>>> recompute = Wizard('product.recompute_cost_price', [product])
>>> recompute.execute('recompute')
>>> [m.cost_price for m in StockMove.find([])]
[Decimal('111.1111'), Decimal('111.1111'), Decimal('106.6666'), Decimal('110.0000'), Decimal('113.3333'), Decimal('113.3333'), Decimal('100.0000')]
>>> [m.product_cost_price for m in StockMove.find([])]
[Decimal('100.0000'), Decimal('100.0000'), None, Decimal('116.6666'), None, None, None]
>>> product.reload()
>>> product.cost_price
Decimal('100.0000')
Recompute cost price from a date::
>>> recompute = Wizard('product.recompute_cost_price', [product])
>>> recompute.form.from_ = today - dt.timedelta(days=1)
>>> recompute.execute('recompute')
>>> [m.cost_price for m in StockMove.find([])]
[Decimal('111.1111'), Decimal('111.1111'), Decimal('106.6666'), Decimal('110.0000'), Decimal('113.3333'), Decimal('113.3333'), Decimal('100.0000')]
>>> product.reload()
>>> product.cost_price
Decimal('100.0000')

View File

@@ -0,0 +1,112 @@
=================================================
Product Cost FIFO Recompute Cost Price Production
=================================================
Imports::
>>> import datetime as dt
>>> 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
>>> today = dt.date.today()
>>> yesterday = today - dt.timedelta(days=1)
Activate modules::
>>> config = activate_modules('product_cost_fifo', create_company)
>>> Location = Model.get('stock.location')
>>> ProductUom = Model.get('product.uom')
>>> ProductTemplate = Model.get('product.template')
>>> StockMove = Model.get('stock.move')
Get company::
>>> company = get_company()
Create product::
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
>>> template = ProductTemplate()
>>> template.name = 'Product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal('50.0000')
>>> template.cost_price_method = 'fifo'
>>> product, = template.products
>>> product.cost_price = Decimal('40.0000')
>>> template.save()
>>> product, = template.products
Get stock locations::
>>> supplier_loc, = Location.find([('code', '=', 'SUP')])
>>> storage_loc, = Location.find([('code', '=', 'STO')])
>>> production_loc = Location(name="Production", type='production')
>>> production_loc.save()
Consume product for production and reverse some::
>>> StockMove(
... product=product,
... quantity=10,
... from_location=storage_loc,
... to_location=production_loc,
... effective_date=today).click('do')
>>> StockMove(
... product=product,
... quantity=2,
... from_location=production_loc,
... to_location=storage_loc,
... unit_price=Decimal('40.0000'),
... currency=company.currency,
... effective_date=today).click('do')
>>> [m.cost_price for m in StockMove.find([])]
[Decimal('40.0000'), Decimal('40.0000')]
>>> [m.product_cost_price for m in StockMove.find([])]
[None, Decimal('40.0000')]
Recompute cost price::
>>> recompute = Wizard('product.recompute_cost_price', [product])
>>> recompute.execute('recompute')
>>> [m.cost_price for m in StockMove.find([])]
[Decimal('0.0000'), Decimal('40.0000')]
>>> [m.product_cost_price for m in StockMove.find([])]
[None, Decimal('0.0000')]
>>> product.reload()
>>> product.cost_price
Decimal('0.0000')
Receive product yesterday at new cost::
>>> StockMove(
... product=product,
... quantity=16,
... from_location=supplier_loc,
... to_location=storage_loc,
... unit_price=Decimal('20.0000'),
... currency=company.currency,
... effective_date=yesterday).click('do')
Recompute cost price::
>>> recompute = Wizard('product.recompute_cost_price', [product])
>>> recompute.execute('recompute')
>>> [m.cost_price for m in StockMove.find([])]
[Decimal('20.0000'), Decimal('20.0000'), Decimal('20.0000')]
>>> [m.product_cost_price for m in StockMove.find([])]
[None, None, Decimal('20.0000')]
>>> product.reload()
>>> product.cost_price
Decimal('20.0000')

View File

@@ -0,0 +1,149 @@
=========================
Stock FIFO Cost Price UoM
=========================
Imports::
>>> import datetime as dt
>>> from decimal import Decimal
>>> from proteus import Model
>>> from trytond.modules.company.tests.tools import create_company, get_company
>>> from trytond.tests.tools import activate_modules
>>> today = dt.date.today()
Activate modules::
>>> config = activate_modules('product_cost_fifo', create_company)
Get company::
>>> company = get_company()
Create product::
>>> ProductUom = Model.get('product.uom')
>>> ProductTemplate = Model.get('product.template')
>>> kg, = ProductUom.find([('name', '=', 'Kilogram')])
>>> g, = ProductUom.find([('name', '=', 'Gram')])
>>> template = ProductTemplate()
>>> template.name = 'Product'
>>> template.default_uom = kg
>>> template.type = 'goods'
>>> template.list_price = Decimal('300')
>>> template.cost_price_method = 'fifo'
>>> product, = template.products
>>> product.cost_price = Decimal('80')
>>> template.save()
>>> product, = template.products
Get stock locations::
>>> Location = Model.get('stock.location')
>>> supplier_loc, = Location.find([('code', '=', 'SUP')])
>>> customer_loc, = Location.find([('code', '=', 'CUS')])
>>> storage_loc, = Location.find([('code', '=', 'STO')])
Make 4 kg of the product available @ 10 ::
>>> StockMove = Model.get('stock.move')
>>> incoming_move = StockMove()
>>> incoming_move.product = product
>>> incoming_move.unit = kg
>>> incoming_move.quantity = 4
>>> incoming_move.from_location = supplier_loc
>>> incoming_move.to_location = storage_loc
>>> incoming_move.planned_date = today
>>> incoming_move.company = company
>>> incoming_move.unit_price = Decimal('10')
>>> incoming_move.currency = company.currency
>>> incoming_move.click('do')
Check Cost Price is 10::
>>> product.reload()
>>> product.cost_price
Decimal('10.0000')
Add 2000 more g @ 0.025::
>>> incoming_move = StockMove()
>>> incoming_move.product = product
>>> incoming_move.unit = g
>>> incoming_move.quantity = 2000
>>> incoming_move.from_location = supplier_loc
>>> incoming_move.to_location = storage_loc
>>> incoming_move.planned_date = today
>>> incoming_move.company = company
>>> incoming_move.unit_price = Decimal('0.025')
>>> incoming_move.currency = company.currency
>>> incoming_move.click('do')
Check Cost Price FIFO is 15::
>>> product.reload()
>>> product.cost_price
Decimal('15.0000')
Sell 3 kg @ 50::
>>> outgoing_move = StockMove()
>>> outgoing_move.product = product
>>> outgoing_move.unit = kg
>>> outgoing_move.quantity = 3
>>> outgoing_move.from_location = storage_loc
>>> outgoing_move.to_location = customer_loc
>>> outgoing_move.planned_date = today
>>> outgoing_move.company = company
>>> outgoing_move.unit_price = Decimal('50')
>>> outgoing_move.currency = company.currency
>>> outgoing_move.click('do')
Check Cost Price FIFO is 20 and cost is 10::
>>> product.reload()
>>> product.cost_price
Decimal('20.0000')
>>> outgoing_move.cost_price
Decimal('10.0000')
Sell twice 1 more kg @ 50::
>>> outgoing_moves = []
>>> outgoing_move = StockMove()
>>> outgoing_move.product = product
>>> outgoing_move.unit = kg
>>> outgoing_move.quantity = 1
>>> outgoing_move.from_location = storage_loc
>>> outgoing_move.to_location = customer_loc
>>> outgoing_move.planned_date = today
>>> outgoing_move.company = company
>>> outgoing_move.unit_price = Decimal('50')
>>> outgoing_move.currency = company.currency
>>> outgoing_move.save()
>>> outgoing_moves.append(outgoing_move)
>>> outgoing_move = StockMove()
>>> outgoing_move.product = product
>>> outgoing_move.unit = g
>>> outgoing_move.quantity = 1000
>>> outgoing_move.from_location = storage_loc
>>> outgoing_move.to_location = customer_loc
>>> outgoing_move.planned_date = today
>>> outgoing_move.company = company
>>> outgoing_move.unit_price = Decimal('0.05')
>>> outgoing_move.currency = company.currency
>>> outgoing_move.save()
>>> outgoing_moves.append(outgoing_move)
>>> StockMove.click(outgoing_moves, 'do')
Check Cost Price FIFO is 25 and costs are 10 and 25::
>>> product.reload()
>>> product.cost_price
Decimal('25.0000')
>>> [m.cost_price for m in outgoing_moves]
[Decimal('10.0000'), Decimal('25.0000')]

View 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 ProductCostFIFOTestCase(ModuleTestCase):
'Test ProductCostFIFO module'
module = 'product_cost_fifo'
del ModuleTestCase

View 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)