【发布时间】:2022-01-08 09:19:46
【问题描述】:
我想遍历所有产品并从另一个字段计算 list_price。 这是我写的代码:
class AedPriceCalculator(models.TransientModel):
_name = "aed.pricecalculator"
_inherit = ['product.template']
aed_current_price = fields.Monetary('current AED price in IRR', required=True, translate=True)
currency_id = fields.Many2one(
'res.currency', 'Currency',default=lambda self: self.env['res.currency'].search([('name', '=', 'AED')]).id,readonly=True)
@api.multi
def price_calculate_ae(self):
products = self.env['product.template'].search(['sale_ok', '=' ,True])
for product in products:
if product.amount_in_aed:
product.list_price = self.aed_current_price * product.amount_in_aed
else:
pass
但是当我调用相关按钮时。 会出现这个错误:
The operation cannot be completed:
- Create/update: a mandatory field is not set.
- Delete: another model requires the record being deleted. If possible, archive it instead.
Model: aed.pricecalculator (aed.pricecalculator), Field: Name(name)
【问题讨论】: