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,26 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr "Фабрична цена"
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr "Дата"
#, fuzzy
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr "Продукт"
#, fuzzy
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Product Cost History"
#, fuzzy
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Product Cost History"

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr "Preu de cost"
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr "Data"
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr "Producte"
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Historial de costos del producte"
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Historial de costos del producte"

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr ""
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr ""
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr ""
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Product Cost History"
#, fuzzy
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Product Cost History"

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr "Einstandspreis"
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr "Datum"
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr "Artikel"
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Historie Kostenpreis"
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Artikel Einstandspreis Historie"

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr "Precio de coste"
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr "Fecha"
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr "Producto"
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Historial de costes del producto"
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Historial de costes del producto"

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr "Precio de costo"
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr ""
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr ""
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr ""
#, fuzzy
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Historial de costos"

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr "Ostuhind"
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr "Kuupäev"
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr "Toode"
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Toote hinna ajalugu"
#, fuzzy
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Toote hinna ajalugu"

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr "ارزش بها"
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr "تاریخ"
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr "محصول"
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "سوابق هزینه محصول"
#, fuzzy
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "سوابق هزینه محصول"

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr ""
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr ""
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr ""
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Product Cost History"
#, fuzzy
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Product Cost History"

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr "Prix de revient"
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr "Date"
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr "Produit"
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Historique du coût du produit"
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Historique du prix de revient de produit"

View File

@@ -0,0 +1,26 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr "Beszerzési ár"
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr "Dátum"
#, fuzzy
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr "Termék"
#, fuzzy
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Product Cost History"
#, fuzzy
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Product Cost History"

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr ""
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr "Tanggal"
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr "Produk"
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr ""
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr ""

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr "Prezzo di costo"
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr "Data"
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr "Prodotto"
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Cronologia del costo del prodotto"
#, fuzzy
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Cronologia del costo del prodotto"

View File

@@ -0,0 +1,27 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
#, fuzzy
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr "ລາຄາຄິດໄລ່"
#, fuzzy
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr "ວັນທີ:"
#, fuzzy
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr "ຜະລິດຕະພັນ"
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Product Cost History"
#, fuzzy
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Product Cost History"

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr ""
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr ""
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr ""
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Product Cost History"
#, fuzzy
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Product Cost History"

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr "Kostprijs"
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr "Datum"
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr "Product"
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Productkostengeschiedenis"
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Productkostengeschiedenis"

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr "Cena fabryczna"
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr "Data"
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr "Produkt"
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Historia kosztów produktu"
#, fuzzy
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Historia kosztów produktu"

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr "Preço de Custo"
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr "Data"
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr "Produto"
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Histórico de Custo do Produto"
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Histórico de Custo do Produto"

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr "Cost"
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr "Data"
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr "Produs"
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Istoricul costurilor produsului"
#, fuzzy
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Istoricul costurilor produsului"

View File

@@ -0,0 +1,26 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr "Цена"
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr "Дата"
#, fuzzy
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr "ТМЦ"
#, fuzzy
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Product Cost History"
#, fuzzy
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Product Cost History"

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr "Nabavna cena"
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr "Datum"
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr "Izdelek"
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Zgodovina stroškov izdelka"
#, fuzzy
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Zgodovina stroškov izdelka"

View File

@@ -0,0 +1,24 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr ""
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr ""
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr ""
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Product Cost History"
#, fuzzy
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Product Cost History"

View File

@@ -0,0 +1,23 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr ""
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr ""
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr ""
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr ""
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr ""

View File

@@ -0,0 +1,25 @@
#
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:product.product.cost_history,cost_price:"
msgid "Cost Price"
msgstr ""
#, fuzzy
msgctxt "field:product.product.cost_history,date:"
msgid "Date"
msgstr "日期格式"
msgctxt "field:product.product.cost_history,product:"
msgid "Product"
msgstr ""
msgctxt "model:ir.action,name:act_product_cost_history_form"
msgid "Product Cost History"
msgstr "Product Cost History"
#, fuzzy
msgctxt "model:product.product.cost_history,string:"
msgid "Product Cost History"
msgstr "Product Cost History"

View File

@@ -0,0 +1,158 @@
# 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 sql import Column, Window
from sql.aggregate import Max
from sql.conditionals import Coalesce
from sql.functions import LastValue
from trytond.model import ModelSQL, ModelView, convert_from, fields
from trytond.modules.product import round_price
from trytond.pool import Pool, PoolMeta
from trytond.tools import timezone as tz
from trytond.transaction import Transaction
class Product(metaclass=PoolMeta):
__name__ = 'product.product'
def get_multivalue(self, name, **pattern):
pool = Pool()
Company = pool.get('company.company')
context = Transaction().context
if (name == 'cost_price'
and context.get('_datetime')
and self.type in ['goods', 'assets']):
datetime = context['_datetime']
company = pattern.get(
'company', Transaction().context.get('company'))
if company is not None and company >= 0:
company = Company(company)
if company.timezone:
timezone = tz.ZoneInfo(company.timezone)
try:
datetime = (
datetime.replace(tzinfo=tz.UTC).astimezone(
timezone))
except OverflowError:
pass
cost_price = self.get_cost_price_at(datetime.date(), **pattern)
if cost_price is not None:
return cost_price
return super().get_multivalue(name, **pattern)
def get_cost_price_at(self, date, **pattern):
pool = Pool()
CostHistory = pool.get('product.product.cost_history')
company = pattern.get(
'company', Transaction().context.get('company'))
with Transaction().set_context(company=company):
records = CostHistory.search([
('date', '<=', date),
('product', '=', self.id),
], limit=1, order=[('date', 'DESC')])
if records:
record, = records
return round_price(record.cost_price)
class CostPrice(metaclass=PoolMeta):
__name__ = 'product.cost_price'
_history = True
class ProductCostHistory(ModelSQL, ModelView):
__name__ = 'product.product.cost_history'
product = fields.Many2One('product.product', "Product")
date = fields.Date('Date')
cost_price = fields.Numeric('Cost Price')
@classmethod
def __setup__(cls):
super().__setup__()
cls._order.insert(0, ('date', 'DESC'))
@classmethod
def table_query(cls):
pool = Pool()
Move = pool.get('stock.move')
Product = pool.get('product.product')
Template = pool.get('product.template')
CostPrice = pool.get('product.cost_price')
User = pool.get('res.user')
move = Move.__table__()
product = Product.__table__()
template = Template.__table__()
history = CostPrice.__table_history__()
transaction = Transaction()
user = User(transaction.user)
tables, clause = Move.search_domain([
('cost_price', '!=', None),
('state', '=', 'done'),
Product._domain_moves_cost(),
['OR',
Product._domain_in_moves_cost(),
Product._domain_out_moves_cost(),
],
], tables={
None: (move, None),
})
cost_price = Coalesce(move.product_cost_price, move.cost_price)
window = Window(
[move.effective_date, move.product],
frame='ROWS', start=None, end=None,
order_by=[move.write_date.asc, move.id.asc])
cost_price = LastValue(cost_price, window=window)
move_history = convert_from(None, tables, type_='INNER').select(
(move.id * 2).as_('id'),
move.effective_date.as_('date'),
move.product.as_('product'),
cost_price.as_('cost_price'),
where=clause)
query = move_history.select(
Max(move_history.id).as_('id'),
move_history.date.as_('date'),
move_history.product.as_('product'),
Max(move_history.cost_price).as_('cost_price'),
group_by=[move_history.date, move_history.product])
if user.company:
timezone = user.company.timezone
else:
timezone = None
price_datetime = Coalesce(history.write_date, history.create_date)
price_date = cls.date.sql_cast(price_datetime, timezone=timezone)
window = Window(
[price_date, history.product],
frame='ROWS', start=None, end=None,
order_by=[price_datetime.asc])
cost_price = LastValue(history.cost_price, window=window)
price_history = (history
.join(product, condition=history.product == product.id)
.join(template, condition=product.template == template.id)
.select(
(Column(history, '__id') * 2 + 1).as_('id'),
price_date.as_('date'),
history.product.as_('product'),
cost_price.as_('cost_price'),
where=~template.type.in_(['goods', 'assets'])
& cls._non_moves_clause(history, user)))
query |= price_history.select(
Max(price_history.id).as_('id'),
price_history.date.as_('date'),
price_history.product.as_('product'),
Max(price_history.cost_price).as_('cost_price'),
group_by=[price_history.date, price_history.product])
return query
@classmethod
def _non_moves_clause(cls, history_table, user):
company_id = user.company.id if user.company else None
return history_table.company == company_id
def get_rec_name(self, name):
return Pool().get('ir.lang').get().strftime(self.date)

View File

@@ -0,0 +1,43 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="product_cost_history_view_tree">
<field name="model">product.product.cost_history</field>
<field name="type">tree</field>
<field name="name">product_cost_history_tree</field>
</record>
<record model="ir.ui.view" id="product_cost_history_view_graph">
<field name="model">product.product.cost_history</field>
<field name="type">graph</field>
<field name="name">product_cost_history_graph</field>
</record>
<record model="ir.action.act_window" id="act_product_cost_history_form">
<field name="name">Product Cost History</field>
<field name="res_model">product.product.cost_history</field>
<field name="domain"
eval="[If(Eval('active_ids', []) == [Eval('active_id')], ('product', '=', Eval('active_id')), ('product', 'in', Eval('active_ids')))]"
pyson="1"/>
</record>
<record model="ir.action.act_window.view" id="act_product_cost_history_form_view1">
<field name="sequence" eval="10"/>
<field name="view" ref="product_cost_history_view_tree"/>
<field name="act_window" ref="act_product_cost_history_form"/>
</record>
<record model="ir.action.act_window.view" id="act_product_cost_history_form_view2">
<field name="sequence" eval="20"/>
<field name="view" ref="product_cost_history_view_graph"/>
<field name="act_window" ref="act_product_cost_history_form"/>
</record>
<record model="ir.action.keyword"
id="act_product_cost_history_keyword1">
<field name="keyword">form_relate</field>
<field name="model">product.product,-1</field>
<field name="action" ref="act_product_cost_history_form"/>
</record>
</data>
</tryton>

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,160 @@
====================
Product Cost History
====================
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, assertEqual
Activate modules::
>>> config = activate_modules('product_cost_history', create_company)
>>> Date = Model.get('ir.date')
Setup company::
>>> company = get_company()
>>> company.timezone = 'Europe/Madrid'
>>> company.save()
>>> today = Date.today(config.context)
>>> now = dt.datetime.combine(today, dt.time())
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('200.0000')
>>> product, = template.products
>>> product.cost_price = Decimal('100.0000')
>>> 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')])
Cost history is empty::
>>> ProductCostHistory = Model.get('product.product.cost_history')
>>> ProductCostHistory.find([])
[]
Create some moves at different dates and with different cost::
>>> StockMove = Model.get('stock.move')
>>> product.cost_price = Decimal('100.0000')
>>> product.save()
>>> StockMove(
... product=product,
... quantity=1,
... from_location=supplier_loc,
... to_location=storage_loc,
... unit_price=Decimal('100.0000'),
... currency=company.currency,
... effective_date=today - dt.timedelta(days=2)).click('do')
>>> modify_cost_price = Wizard('product.modify_cost_price', [product])
>>> modify_cost_price.form.cost_price = '90.0000'
>>> modify_cost_price.execute('modify')
>>> StockMove(
... product=product,
... quantity=1,
... from_location=supplier_loc,
... to_location=storage_loc,
... unit_price=Decimal('90.0000'),
... currency=company.currency,
... effective_date=today - dt.timedelta(days=1)).click('do')
>>> modify_cost_price = Wizard('product.modify_cost_price', [product])
>>> modify_cost_price.form.cost_price = '120.0000'
>>> modify_cost_price.execute('modify')
>>> StockMove(
... product=product,
... quantity=1,
... from_location=supplier_loc,
... to_location=storage_loc,
... unit_price=Decimal('120.0000'),
... currency=company.currency,
... effective_date=today - dt.timedelta(days=1)).click('do')
>>> modify_cost_price = Wizard('product.modify_cost_price', [product])
>>> modify_cost_price.form.cost_price = '110.0000'
>>> modify_cost_price.execute('modify')
>>> StockMove(
... product=product,
... quantity=1,
... from_location=supplier_loc,
... to_location=storage_loc,
... unit_price=Decimal('110.0000'),
... currency=company.currency,
... effective_date=today).click('do')
Check cost history::
>>> order = [('date', 'ASC')]
>>> [c.cost_price for c in ProductCostHistory.find([], order=order)]
[Decimal('100.0000'), Decimal('120.0000'), Decimal('110.0000')]
>>> assertEqual([c.date for c in ProductCostHistory.find([], order=order)], [
... today - dt.timedelta(days=2),
... today - dt.timedelta(days=1),
... today])
Check cost price history on product::
>>> product.reload()
>>> product.cost_price
Decimal('110.0000')
>>> with config.set_context(_datetime=now - dt.timedelta(days=3)):
... product = Product(product.id)
>>> product.cost_price
Decimal('0')
>>> with config.set_context(_datetime=now - dt.timedelta(days=2)):
... product = Product(product.id)
>>> product.cost_price
Decimal('100.0000')
>>> with config.set_context(_datetime=now - dt.timedelta(days=1)):
... product = Product(product.id)
>>> product.cost_price
Decimal('120.0000')
Create service::
>>> template = ProductTemplate()
>>> template.name = 'Service'
>>> template.default_uom = unit
>>> template.type = 'service'
>>> template.list_price = Decimal('50.0000')
>>> service, = template.products
>>> service.cost_price = Decimal('30.0000')
>>> template.save()
>>> sevice, = template.products
Update cost price::
>>> service.cost_price += 5
>>> service.save()
Check cost history::
>>> history, = ProductCostHistory.find([('product', '=', service.id)])
>>> history.cost_price
Decimal('35.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 ProductCostHistoryTestCase(ModuleTestCase):
'Test ProductCostHistory module'
module = 'product_cost_history'
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)

View File

@@ -0,0 +1,14 @@
[tryton]
version=7.8.0
depends:
ir
product
stock
xml:
product.xml
[register]
model:
product.Product
product.CostPrice
product.ProductCostHistory

View File

@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<graph type="line">
<x>
<field name="date"/>
</x>
<y>
<field name="cost_price" fill="1" empty="0"/>
</y>
</graph>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tree>
<field name="product"/>
<field name="date"/>
<field name="cost_price"/>
</tree>