Odoo 도움말


1 응답

Ibrahim Boudmir Morocco

--Ibrahim Boudmir--
| 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') 


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.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.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now