Skip to Content
Menú
This question has been flagged

Okay so i solved it. Just switched x_survey_id with an existing survey_id in survey.user_input as relation field in survey.survey. But now I can't calculate the fields. I want to use x_rate field from survey.survey model but the other field (x_amount_payable) i want to calculate with x_rate and the field (x_total_paying_fjd) in which it will be displayed is in survey.user_input model. How can I compute x_total_paying_fjd = x_amount_payable/x_rate?


So I'm very new to odoo and I've been tasked to create a one2many field from front end/interface. I have to create the "Add a line.." function that opens a new form to enter details and save to table.

 I used pre-existing models to create a one2many field since I don't have backend access to create models for now. I used survey.survey as my main model to implement the one2may field (x_survey_line_ids) and  survey.user_input as the sub-model with all other fields I want displayed (x_date, x_amount, x_amount_payable, x_invoice_id - many2one[account.asset.asset], x_purchase_order, x_receipt, x_remarks, x_survey_id - many2one[survey.survey], x_total_paying_fjd, x_wht1, x_wht2). 


This is my code in Edit:View Form of survey.survey.


 
                             
                               
                               
                               
                               
                               
                               
                               
                               
                               
                               
                             
                             
                               
                                   
                                   
                                   
                                   
                                   
                                   
                                   
                                   
                                   
                                   
                               
                             
                           


I've used x_survey_id  as the relation field and survey.user_input as object relation for x_survey_line_ids.


I can add a line and enter information in the new form that opens but it gives this error when trying to save. What can I do from front end to solve it?


"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: Survey User Input (survey.user_input), Field: Survey (survey_id)"

Avatar
Descartar
Best Answer

from odoo import models, fields, api

from odoo.exceptions import UserError


class SurveyUserInput(models.Model):

    _name = 'survey.user_input'

    

    x_date = fields.Date(string='Date', required=True)

    x_amount = fields.Float(string='Amount', required=True)

    x_amount_payable = fields.Float(string='Amount Payable', required=True)

    # Other fields...

    x_survey_id = fields.Many2one('survey.survey', string='Survey', required=True)


    @api.constrains('x_date', 'x_amount', 'x_amount_payable', 'x_invoice_id', 'x_survey_id')

    def _check_mandatory_fields(self):

        for record in self:

            if not all([record.x_date, record.x_amount, record.x_amount_payable, record.x_invoice_id, record.x_survey_id]):

                raise UserError('Please fill in all mandatory fields.')


Avatar
Descartar
Related Posts Respostes Vistes Activitat
1
de febr. 24
1461
0
d’oct. 22
2136
0
d’abr. 21
3430
0
de febr. 21
3743
1
de març 23
2283