这种方法应该只显示具有相同字段的特定选定财政年度内的报告期



为了清晰起见,这里有代码:

class ProgrammeLinking(models.Model):
_name = 'mis.programme.linking'
_description = 'linking and allocations'
_rec_name = "financial_year_id"

financial_year_id = fields.Many2one('res.financial.year',string='Financial Year')

output_indicator_id = fields.Many2one('mis.output.indicator',string='APP Output indicator', store=True)
allowed_output_indicator_ids = fields.Many2many(
'mis.output.indicator', 
compute="_compute_allowed_output_indicator_ids"
)
reporting_period_id = fields.Many2one('mis.create.link.national.app', string='Reporting Period')
allowed_reporting_period_ids = fields.Many2many(
'mis.create.link.national.app',
compute="_compute_allowed_reporting_period_ids"
)

def _get_current_fy_programme_linking(self):
for rec in self:
return self.env['mis.create.link.national.app'].search([
('financial_year_id','=', rec.financial_year_id.id)
])

@api.depends('outcome_id')
def _compute_allowed_output_indicator_ids(self):
for rec in self:
if rec.outcome_id:
fy_linkings = self._get_current_fy_programme_linking()
output = fy_linkings 
.filtered(lambda l: l.outcome_id.id == rec.outcome_id.id) 
.mapped('output_indicator_id')
_logger.info(f"Filtered ou {output}")
rec.allowed_output_indicator_ids = output
else:
rec.allowed_output_indicator_ids = False

@api.depends('output_indicator_id')
def _compute_allowed_reporting_period_ids(self):
for rec in self:
if rec.output_indicator_id:
fy_linkings = self._get_current_fy_programme_linking()
period = fy_linkings 
.filtered(lambda l: l.output_indicator_id.id == rec.output_indicator_id.id) 
.mapped('reporting_period')
_logger.info(f"Filtered periods {period}")
rec.allowed_reporting_period_ids = period
else:
rec.allowed_reporting_period_ids = False

视图中的:

<field name="allowed_output_indicator_ids" invisible="1"/>
<field name="output_indicator_id" required="1" options="{'no_create': True, 'no_open': True}" domain="[('id','in', allowed_output_indicator_ids)]"/>
<field name="allowed_reporting_period_ids" invisible="1"/>
<field name="reporting_period_id" required="1" options="{'no_create': True, 'no_open': True}" domain="[('id','in', allowed_reporting_period_ids)]"/>

现在,当我点击字段";reporting_period_;我得到的错误是:

Traceback (most recent call last):
File "C:odoo14serverodoohttp.py", line 639, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "C:odoo14serverodoohttp.py", line 315, in _handle_exception
raise exception.with_traceback(None) from new_cause
psycopg2.errors.InvalidTextRepresentation: invalid input syntax for type integer: "quarterly"
LINE 1: ...p" WHERE ("mis_create_link_national_app"."id" in ('quarterly...
^

报告期是我正在搜索的类别中的选择字段,并且它在所选财政年度中的值是"0";季度";但我犯了这个错误。

我很感谢你的帮助

错误:

psycopg2.errors.InvalidTextRepresentation: invalid input syntax for type integer: "quarterly"
LINE 1: ...p" WHERE ("mis_create_link_national_app"."id" in ('quarterly...

似乎没有直接链接到您提供的代码,因为错误涉及:

mis_create_link_national_app.id 

它是一个整数和sql操作:

IN

并且一个整数不能在字符串列表中(在您的情况下:"quarterly"(

解决方案:用相应的记录id替换"quadry"(您可能只需在查询中的字段名后面添加.id(

该问题是由.mapped('reporting_period'(引起的,它将返回报告期列表:

['quarterly', ...]

然后Odoo将无法设置/获取allowed_reporting_period_ids字段的值

要解决此问题,您可以简单地删除mapped(Odoo接受将记录集分配给字段(

相关内容

  • 没有找到相关文章

最新更新