Odoo Help

0

0
2 Answers
1
Avatar

Manish Kumar Bohra

--Manish Kumar Bohra--
8801
| 6 4 10
Bikaner, Índia
--Manish Kumar Bohra--


Manish Kumar Bohra
09/10/17 03:25

Hello Pawan , 

You can  add this in your .py file Imported  "odoo.exceptions import UserError"   

0
Avatar

Ibrahim

--Ibrahim--
2807
| 6 3 7
Casablanca, Marrocos
--Ibrahim--


Ibrahim
08/10/17 08:28

Hi Pawan,

I suppose that machine_weight_id in M2O, since you wrote it that way.

weight_total = Fields.Float(..., compute='_compute_total_weight') 

@api.multi

def get_total_weight(self):

 total= 0;

 if self.machine_weight_id:

     weight_obj = self.env['your comodel_name'].search([])

     #here it returns all records in the model

     for rec in machine_weight_id:

     #here you can access each records using rec

         if rec.weight:

             total += rec.weight

 return total

@api.multi

@api.depends('machine_weight_id', 'weight')

def _compute_total_weight(self):

for record in self:

    record.weight_total = record.get_total_weight()

    if record.weight_total >= 50.00:

          raise UserError(_('Weight Exceeded'))

UserError should be imported : from odoo.exceptions import UserError

Ask a Question
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now