Odoo 도움말

0

0
1 응답
0
Avatar

Ibrahim Boudmir Morocco

--Ibrahim Boudmir--
5482
| 6 3 7
Casablanca, Morocco
--Ibrahim Boudmir--


Ibrahim Boudmir Morocco
17. 10. 8. 오전 8: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

질문하기
Keep Informed
1 팔로워
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 E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now