Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
1241 Lượt xem
  File "/home/gowtham.a/workspace/odoo-18.0/odoo/models.py", line 6880, in __getitem__
    return self._fields[key].__get__(self)
  File "/home/gowtham.a/workspace/odoo-18.0/odoo/fields.py", line 1296, in __get__
    raise ValueError(f"Compute method failed to assign {missing_recs}.{self.name}")
ValueError: Compute method failed to assign account.move(2,).exchange_rate


class AccountMove(models.Model):   
_inherit = "account.move"

attn = fields.Many2one('res.partner',string="ATTN")
customer_po_no = fields.Char(string="Customer PO No.")
do_name = fields.Char(string="DO No.")
exchange_rate = fields.Float(string="Rate",digits=(12,4),compute="_compute_currency_rate")


def _compute_currency_rate(self):
for mov in self:
if mov.currency_id:

if mov.company_id.country_id.code != 'SG':
currency_id_rates = self.env['res.currency.rate'].search([('currency_id','=',mov.currency_id.id),('company_id','=',mov.company_id.id)])
for currency_id_rate in currency_id_rates:
if currency_id_rate.name == mov.invoice_date:

mov.exchange_rate = currency_id_rate.rate
break
else:
if mov.invoice_date and currency_id_rate.name:
if currency_id_rate.name.month == mov.invoice_date.month and currency_id_rate.name.year == mov.invoice_date.year:
mov.exchange_rate = currency_id_rate.rate
break
else:
mov.exchange_rate = currency_id_rate.rate
else:
mov.exchange_rate = currency_id_rate.rate
break
else:
currency_id_rates = self.env['res.currency.rate'].search([('currency_id','=',mov.currency_id.id),('company_id','=',mov.company_id.id)])
for currency_id_rate in currency_id_rates:
if currency_id_rate.name == mov.invoice_date:
mov.exchange_rate = 1 / currency_id_rate.rate
break
else:
if mov.invoice_date and currency_id_rate.name:
if currency_id_rate.name.month == mov.invoice_date.month and currency_id_rate.name.year == mov.invoice_date.year:
mov.exchange_rate = 1 / currency_id_rate.rate
break
else:
mov.exchange_rate = 1 / currency_id_rate.rate
else:
mov.exchange_rate = 1 / currency_id_rate.rate
break

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Probably it happens, because this compute field is left unassigned from your function. So better to add some default value to avoid unassigned cases such as or make sure it is never left unassigned by modifying your function:

def _compute_currency_rate(self):
    for mov in self:
        mov.exchange_rate = 1.0  # Default value to avoid unassigned cases
​....
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 4 25
1194
0
thg 11 24
749
0
thg 8 25
23
0
thg 8 25
159
0
thg 8 25
183