如何更新另一个模型.Many2one字段.Odoo-14



我将account.reconciliation.act模型中的数据创建到direct中。统计模型然后我想更改account.reconciliation.act中的一些数据。它的方向不变。统计模型。我写了一个写方法,我想直接更新数据。统计模型。但这行不通。我做错了什么?

我得到TypeError错误:write()接受2个位置参数,但给出了3个py 1.

class AccountReconciliationAct(models.Model):
_name = "account.reconciliation.act"
direct_statistics_id = fields.Many2one(comodel_name="direct.statistics", string="Direct Statistics")
@api.model
def create(self, values):
....
else:
self.env["direct.statistics"].create({
"direct_advertiser_id": record_id.partner_id.id,
"direct_payment_net_id": record_id.payment_net_id.id,
"direct_currency_id": record_id.currency_id.id,
"direct_last_act_date": record_id.reconciliation_act_date,
"direct_total_amount": record_id.amount_total,
"direct_department_ids": record_id.reconciliation_act_line_ids.department_id
})
return record_id
@api.model
def write(self, values):
res = super().write(values)
self.env["direct.statistics"].update({
"direct_advertiser_id": self.partner_id.id,
"direct_payment_net_id": self.payment_net_id.id,
"direct_currency_id": values.get('currency_id.id'),
"direct_last_act_date": values.get('reconciliation_act_date'),
"direct_total_amount": values.get('amount_total'),
"direct_department_ids": values.get('reconciliation_act_line_ids.department_id'),
})
return res

py 2.

class DirectStatistics(models.Model):
_name = "direct.statistics"
_description = "Direct statistics"
_rec_name = "direct_advertiser_id"
direct_advertiser_id = fields.Many2one(comodel_name="res.partner", string="Advertiser")
direct_manager_id = fields.Many2one(related="direct_advertiser_id.manager_id", string="Manager")
direct_payment_net_id = fields.Many2one(related="direct_advertiser_id.payment_net_id", string="Net")
direct_currency_id = fields.Many2one(comodel_name="res.currency", string="Currency")
direct_conversion_ids = fields.Many2many(comodel_name="affise.conversion", string="Conversions")
direct_last_act_date = fields.Date(string="Last Act Date", compute="_compute_direct_last_act_date", store=True)
direct_first_conversion_date = fields.Date(
string="First Conversion Date", compute="_compute_direct_first_conversion_date", store=True
)
direct_department_ids = fields.Many2many(
comodel_name="affise.department", compute="_compute_direct_department_ids", string="Department"
)
direct_reconciliation_act_ids = fields.Many2many(
comodel_name="account.reconciliation.act", string="Created Acts", domain=[("state", "!=", "cancel")]
)
direct_total_amount = fields.Monetary(
currency_field="direct_currency_id", string="Total Acts")
class AccountReconciliationAct(models.Model):
_name = "account.reconciliation.act"
direct_statistics_id = fields.Many2one(comodel_name="direct.statistics", string="Direct Statistics")
@api.model
def create(self, values):
record_id = super(AccountReconciliationAct, self).create(values)
....
else:
record_id.direct_statistics_id = self.env["direct.statistics"].create({
"direct_advertiser_id": record_id.partner_id.id,
"direct_payment_net_id": record_id.payment_net_id.id,
"direct_currency_id": record_id.currency_id.id,
"direct_last_act_date": record_id.reconciliation_act_date,
"direct_total_amount": record_id.amount_total,
"direct_department_ids": record_id.reconciliation_act_line_ids.department_id
})
return record_id
def write(self, values):
res = super(AccountReconciliationAct, self).write(values)
self.direct_statistics_id.update({
"direct_advertiser_id": self.partner_id.id,
"direct_payment_net_id": self.payment_net_id.id,
"direct_currency_id": values.get('currency_id.id'),
"direct_last_act_date": values.get('reconciliation_act_date'),
"direct_total_amount": values.get('amount_total'),
"direct_department_ids": values.get('reconciliation_act_line_ids.department_id'),
})
return res

您需要做的第一件事是将创建的对象写入direct_statistics_id字段。这样做是为了更新write方法中的值。也不需要调用@api.model的写方法。

相关内容

  • 没有找到相关文章

最新更新