Odoo:更新相关字段而不更改其原始值
Odoo: updating related field without changing it's original value
我正在尝试更新模型 custom.sale.line
中与模型 custom.price
中的字段 product_id.sell_price
相关的字段 price
但不影响后者的原始值(在其他方式我希望收银员能够更改销售发票上的值但不更改数据库中产品的值),我想知道是否有任何更改可以这样做
我尝试创建另一个字段 other_price
,它采用 price
的值,但即使使用 store=True
,它也不会在数据库中保存新值并恢复为原始值
如果有人能解决这个问题,我将不胜感激
下面是代码
class CustomSaleLine(models.Model):
_name = 'custom.sale.line'
_sql_constraints = [
('product_br_uniq', 'unique(order_id, product_id)',
'Cannot add a product that already exists')]
product_id = fields.Many2one(comodel_name="custom.product", string="Product",
domain="[('branch_line.branch_id.user_lines.user_id','=', user_id)]")
sell_price = fields.Float(string='Main Price', related='product_id.sell_price', required=True, )
other_price = fields.Float(string='Other Price', compute='_compute_price', store=True)
store=True, )
@api.depends('sell_price')
def _compute_price(self):
for rec in self:
rec.other_price = rec.sell_price
尝试
sell_price = fields.Float(string='Main Price', inverse='_compute_dummy', compute='_compute_price', required=True, store=True)
@api.depends('product_id.sell_price')
def _compute_price(self):
for rec in self:
rec.sell_price = rec.product_id.sell_price
def _compute_dummy(self):
pass
我正在尝试更新模型 custom.sale.line
中与模型 custom.price
中的字段 product_id.sell_price
相关的字段 price
但不影响后者的原始值(在其他方式我希望收银员能够更改销售发票上的值但不更改数据库中产品的值),我想知道是否有任何更改可以这样做
我尝试创建另一个字段 other_price
,它采用 price
的值,但即使使用 store=True
,它也不会在数据库中保存新值并恢复为原始值
如果有人能解决这个问题,我将不胜感激
下面是代码
class CustomSaleLine(models.Model):
_name = 'custom.sale.line'
_sql_constraints = [
('product_br_uniq', 'unique(order_id, product_id)',
'Cannot add a product that already exists')]
product_id = fields.Many2one(comodel_name="custom.product", string="Product",
domain="[('branch_line.branch_id.user_lines.user_id','=', user_id)]")
sell_price = fields.Float(string='Main Price', related='product_id.sell_price', required=True, )
other_price = fields.Float(string='Other Price', compute='_compute_price', store=True)
store=True, )
@api.depends('sell_price')
def _compute_price(self):
for rec in self:
rec.other_price = rec.sell_price
尝试
sell_price = fields.Float(string='Main Price', inverse='_compute_dummy', compute='_compute_price', required=True, store=True)
@api.depends('product_id.sell_price')
def _compute_price(self):
for rec in self:
rec.sell_price = rec.product_id.sell_price
def _compute_dummy(self):
pass