I want to change the value of Ordered Qty (product_uom_qty
) and prix unitaire (price_unit
) when changing the Ligne Contrat. But my onchange
functions only work for the Ordered Qty, although both functions are called correctly.
Here is my code :
from datetime import datetime, timedelta
from odoo import api, fields, models, _
# Contrat model
class Contrat(models.Model):
_name = 'contrat.contrat'
_rec_name = 'contrat_name'
contrat_name = fields.Char(string='Nom')
contrat_number = fields.Integer(string="Numero")
date_start = fields.Date(string='Date Debut')
date_end = fields.Date(string="Date Fin")
date_deadline = fields.Date(string="date echeance")
ligne_id = fields.One2many('contrat.lignes','ligne_ids',"mylignes")
# notebook_ids = fields.Many2one('contrat.lignes','ligne_id',string='Notebook')
client_name = fields.Many2one('res.partner',string="Client")
bons_ligne_ids = fields.One2many('sale.order.line', 'contrat_name_id', String='Contrat bons')
class ContratOrder(models.Model):
_name = 'contrat.lignes'
_rec_name = 'ligne_name'
ligne_ids = fields.Many2one('contrat.contrat',string="Contrat")
ligne_name = fields.Char(string="Nom de Ligne")
unit_price = fields.Float(string='Prix Unitaire')
article_name = fields.Many2one('product.template', string="Article")
quantity = fields.Float(string='Quantite')
# modifier les lignes des bons de commands
class bons_lignes(models.Model):
_inherit="sale.order.line"
bons_po = fields.Integer('PO')
contrat_name_id = fields.Many2one('contrat.contrat', string='Contrat')
contrat_lignes_id = fields.Many2one('contrat.lignes', string='Ligne contrat')
product_uom_qty = fields.Float('qtt', related='contrat_lignes_id.quantity')
price_unit = fields.Float(string='Prix Unitaire')
@api.onchange('contrat_lignes_id')
def onchange_conrat_lignes_id(self):
self.price_unit = self.contrat_lignes_id.unit_price
How is it possible to change both fields with one or more onchange functions.
EDIT: Odoo already has a onchange trigger on field product_uom_qty
which is changing the field price_unit
after calling my onchange methods. How is it possible to get my onchange functions get called later, or just forbid Odoo to call its other functions?