콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
7330 화면


def test_change_forecasting_config_of_products(self):
"Change forecasting configuration of products"
forecast_group = self.Forecast_Group.search([('name', '=', 'C')])
product_product = self.Product_Product.search([('name', '=', 'Large Cabinet')])
product_product.forecast_group_id = forecast_group # enter the computing method 1st time
self.assertEqual(
[product_product.no_periods, product_product.period_type, product_product.first_date_of_period],
[forecast_group.periods_to_forecast, forecast_group.period_type, forecast_group.first_date])

product_product.auto_update = False # enter the computing method 2nd time

In the above code i am trying to edit the computed filed mannally in a test method

And this is the method using for computing



@api.depends('auto_update',
'forecast_group_id',
'forecast_group_id.period_type',
'forecast_group_id.periods_to_forecast',
'forecast_group_id.first_date')
def _compute_forecasting(self):
# custom prefetch
cache = {
record['id']: {'first_date_of_period': record['first_date_of_period'],'period_type': record['period_type'], 'no_periods': record['no_periods']}
for record in self.read(['first_date_of_period', 'period_type', 'no_periods'])
}# removing this line will make the product variable below return to empty value
for product in self:
if product.auto_update:
product.first_date_of_period = product.forecast_group_id.first_date
product.period_type = product.forecast_group_id.period_type
product.no_periods = product.forecast_group_id.periods_to_forecast

My computed fields:


period_type = fields.Selection(PeriodType.LIST_PERIODS, compute='_compute_forecasting', store=True)
no_periods = fields.Integer(string="Number of Periods", compute='_compute_forecasting', store=True)
first_date_of_period = fields.Datetime(compute='_compute_forecasting', store=True)

From what I know i should not be allowed to change the computed field manually without using inverse method, but when i tested this Odoo did not throw any error. Can anyone explain for me   ?

And there is another question, if i remove the "cache" variable, the second time the computing function triggered the new value of product that is changed in the first time the function is triggered is not return. Why does this happen ?


아바타
취소
베스트 답변

Hello Dang,

Compute field values are updated when the values of the fields which are in depends of the compute method are changed.

In your test method you can directly call the compute method: record._compute_forecasting()
And then you can test the compute result based on assert condition.

Regards,




Email: odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

   

아바타
취소
관련 게시물 답글 화면 활동
compute issue 해결 완료
1
5월 21
4009
1
6월 25
15904
3
4월 25
6290
Compute Fields 해결 완료
2
7월 24
6543