[IMP] stock_account: removed useless test suite, changed the historization of cost price of products
bzr revid: qdp-launchpad@openerp.com-20131029130153-0zrdwdycpks2tos2
This commit is contained in:
parent
d942803243
commit
acb241ed37
|
@ -195,18 +195,6 @@ class stock_location_route(osv.osv):
|
|||
# Quants
|
||||
#----------------------------------------------------------
|
||||
|
||||
# Useful model for the stock_quant_move_rel many2many relation table.
|
||||
# In particular provide a ID column used in reporting (see the quant_history
|
||||
# model).
|
||||
class quant_history_rel(osv.osv):
|
||||
_name = 'quant.history.rel'
|
||||
_table = 'stock_quant_move_rel'
|
||||
|
||||
_columns = {
|
||||
'move_id': fields.many2one('stock.move'),
|
||||
'quant_id': fields.many2one('stock.quant'),
|
||||
}
|
||||
|
||||
class stock_quant(osv.osv):
|
||||
"""
|
||||
Quants are the smallest unit of stock physical instances
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
'author': 'OpenERP SA',
|
||||
'summary': 'Inventory, Logistic, Valuation, Accounting',
|
||||
'description': """
|
||||
TODO
|
||||
#TODO
|
||||
======================
|
||||
TODO
|
||||
#TODO
|
||||
|
||||
Key Features
|
||||
------------
|
||||
|
|
|
@ -7,23 +7,22 @@ wuants creation.
|
|||
|
||||
"""
|
||||
|
||||
import openerp
|
||||
from openerp.osv import expression
|
||||
from openerp import tools
|
||||
from openerp.osv import fields, osv
|
||||
|
||||
class price_history(openerp.osv.orm.Model):
|
||||
class price_history(osv.osv):
|
||||
|
||||
_name = 'price.history'
|
||||
_rec_name = 'datetime'
|
||||
|
||||
_columns = {
|
||||
'company_id': openerp.osv.fields.many2one('res.company',
|
||||
required=True),
|
||||
'product_id': openerp.osv.fields.many2one('product.product'), # required = True
|
||||
'datetime': openerp.osv.fields.datetime(),
|
||||
'cost': openerp.osv.fields.float(), # called standard_price on
|
||||
# product.product
|
||||
'reason': openerp.osv.fields.char(),
|
||||
'company_id': fields.many2one('res.company', required=True),
|
||||
'product_id': fields.many2one('product.product', 'Product', required=True),
|
||||
'datetime': fields.datetime('Historization Time'),
|
||||
'cost': fields.float('Historized Cost'),
|
||||
'reason': fields.char('Reason'),
|
||||
# TODO 'origin': openerp.osv.fields.reference(),
|
||||
'quant_id': openerp.osv.fields.many2one('stock.quant'),
|
||||
#'quant_id': openerp.osv.fields.many2one('stock.quant'),
|
||||
}
|
||||
|
||||
def _get_default_company(self, cr, uid, context=None):
|
||||
|
@ -35,45 +34,49 @@ class price_history(openerp.osv.orm.Model):
|
|||
return company.id if company else False
|
||||
|
||||
_defaults = {
|
||||
'quant_id': False,
|
||||
'datetime': openerp.osv.fields.datetime.now,
|
||||
#'quant_id': False,
|
||||
'datetime': fields.datetime.now,
|
||||
'company_id': _get_default_company,
|
||||
}
|
||||
|
||||
class quant_history(openerp.osv.orm.Model):
|
||||
|
||||
_name = 'quant.history'
|
||||
|
||||
class stock_history(osv.osv):
|
||||
_name = 'stock.history'
|
||||
_auto = False
|
||||
|
||||
_columns = {
|
||||
'id': openerp.osv.fields.integer(),
|
||||
'move_id': openerp.osv.fields.many2one('stock.move'),
|
||||
'quant_id': openerp.osv.fields.many2one('stock.quant'),
|
||||
'location_id': openerp.osv.fields.many2one('stock.location'),
|
||||
'product_id': openerp.osv.fields.many2one('product.product'),
|
||||
'quantity': openerp.osv.fields.integer(),
|
||||
'date': openerp.osv.fields.datetime(),
|
||||
'cost': openerp.osv.fields.float(),
|
||||
'move_id': fields.many2one('stock.move', 'Stock Move'),
|
||||
#'quant_id': fields.many2one('stock.quant'),
|
||||
'location_id': fields.many2one('stock.location', 'Location'),
|
||||
'product_id': fields.many2one('product.product', 'Product'),
|
||||
'quantity': fields.integer('Quantity'),
|
||||
'date': fields.datetime('Date'),
|
||||
'cost': fields.float('Value'),
|
||||
}
|
||||
|
||||
def init(self, cr):
|
||||
openerp.tools.drop_view_if_exists(cr, 'stock_valuation')
|
||||
tools.drop_view_if_exists(cr, 'stock_history')
|
||||
cr.execute("""
|
||||
create or replace view quant_history as (
|
||||
select
|
||||
history.id as id,
|
||||
history.move_id as move_id,
|
||||
history.quant_id as quant_id,
|
||||
stock_quant.location_id as location_id,
|
||||
stock_quant.product_id as product_id,
|
||||
stock_quant.qty as quantity,
|
||||
stock_move.date as date,
|
||||
(select price_history.cost from price_history where price_history.datetime < stock_move.date order by price_history.datetime asc limit 1) as cost
|
||||
from
|
||||
stock_quant_move_rel as history
|
||||
left join
|
||||
stock_move on stock_move.id = history.move_id
|
||||
left join
|
||||
stock_quant on stock_quant.id = history.quant_id
|
||||
CREATE OR REPLACE VIEW stock_history AS (
|
||||
SELECT
|
||||
stock_move.id AS id,
|
||||
stock_move.id AS move_id,
|
||||
stock_move.location_id AS location_id,
|
||||
stock_move.product_id AS product_id,
|
||||
stock_move.product_qty AS quantity,
|
||||
stock_move.date AS date,
|
||||
CASE
|
||||
WHEN ir_property.value_text <> 'real'
|
||||
THEN (SELECT price_history.cost FROM price_history WHERE price_history.datetime <= stock_move.date AND price_history.product_id = stock_move.product_id ORDER BY price_history.datetime ASC limit 1)
|
||||
ELSE stock_move.price_unit
|
||||
END AS cost
|
||||
FROM
|
||||
stock_move
|
||||
LEFT JOIN
|
||||
product_product ON product_product.id = stock_move.product_id
|
||||
LEFT JOIN
|
||||
product_template ON product_template.id = product_product.product_tmpl_id
|
||||
LEFT JOIN
|
||||
ir_property ON (ir_property.name = 'cost_method' and ir_property.res_id = 'product.template,' || product_template.id::text)
|
||||
WHERE stock_move.state = 'done'
|
||||
)""")
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Tests for the stock_account module.
|
||||
|
||||
This module groups a few sub-modules containing unittest2 test cases.
|
||||
|
||||
Tests can be explicitely added to the `fast_suite` or `checks` lists or not.
|
||||
See the :ref:`test-framework` section in the :ref:`features` list.
|
||||
"""
|
||||
|
||||
import test_standard_prices
|
||||
|
||||
fast_suite = [
|
||||
]
|
||||
|
||||
checks = [
|
||||
test_standard_prices,
|
||||
]
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -1,55 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import unittest2
|
||||
|
||||
import openerp
|
||||
from openerp.tests import common
|
||||
|
||||
|
||||
class test_transaction_case(common.TransactionCase):
|
||||
|
||||
def _test_00(self):
|
||||
cr, uid = self.cr, self.uid
|
||||
location_id = self.registry('stock.location').create(cr, uid,
|
||||
{'name': 'Test Location A'})
|
||||
product_id = self.registry('product.product').create(cr, uid,
|
||||
{
|
||||
'name': 'Test Product A',
|
||||
'standard_price': 1,
|
||||
})
|
||||
value = self.registry('stock.value')._get_value(cr, uid,
|
||||
location_id, product_id, openerp.osv.fields.datetime.now())
|
||||
self.assertEqual(value, 0)
|
||||
|
||||
def _test_01(self):
|
||||
cr, uid = self.cr, self.uid
|
||||
stock_location_company = self.registry('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_company')
|
||||
location_id = self.registry('stock.location').create(cr, uid,
|
||||
{'name': 'Test Location A'})
|
||||
product_id = self.registry('product.product').create(cr, uid,
|
||||
{
|
||||
'name': 'Test Product A',
|
||||
'standard_price': 1,
|
||||
})
|
||||
product = self.registry('product.product').browse(cr, uid, product_id)
|
||||
move_id = self.registry('stock.move').create(cr, uid,
|
||||
{
|
||||
'name': 'Test Stock Move 1',
|
||||
'product_id': product_id,
|
||||
'location_id': stock_location_company.id, # arbitrary source location
|
||||
'location_dest_id': location_id,
|
||||
'product_uom_qty': 10,
|
||||
'product_uom': product.uom_id.id,
|
||||
})
|
||||
value = self.registry('stock.value')._get_value(cr, uid,
|
||||
location_id, product_id, openerp.osv.fields.datetime.now())
|
||||
self.assertEqual(value, 0)
|
||||
|
||||
self.registry('stock.move').action_done(cr, uid, [move_id])
|
||||
value = self.registry('stock.value')._get_value(cr, uid,
|
||||
location_id, product_id, openerp.osv.fields.datetime.now())
|
||||
self.assertEqual(value, 10)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest2.main()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
Loading…
Reference in New Issue