Odoo Ayuda

0

0
3 Answers
0
Maks
4/12/18 8:15

Thanks for answers, but none of them work. However, I found the solution on my own. Here it is:

class WebsiteSupportUpgradePartners(models.Model):
_inherit = "res.partner"

@api.multi
@api.onchange('sla_id')
def sla_inheritence(self):
if self.company_type == 'company':
if self.child_ids and self.sla_id:
parent_sla = self.env['website.support.sla'].search([('id', '=', self.sla_id.id)])
for child in self.child_ids:
child.write({'sla_id': parent_sla.id})

I don't really know why previous code didn't work, even if logs showed otherwise, but this one is doing fine. For me, issue is closed.

0
Mayank Gosai
3/12/18 18:13

Hello Maks,

Yes it is possible.

But make sure you override the existing create and write function of the corresponding model

For Example:

class ProductTemplate(models.Model):

     _inherit = "product.template"

     custom_field = fields.Char("Custom Field", readonly=True)


     @api.onchange('ref_field')
     def onchange_value(self):

         if self.ref_field:

             self.custom_field = "Your Value"


     @api.model

     def create(self, vals):

         vals['custom_field'] = "Your Value"

         res = super(ProductTemplate, self).create(vals)

         return res


     @api.multi

     def write(self, vals):

         vals['custom_field'] = "Your Value"

         res = super(ProductTemplate, self).write(vals)

       return res.

Hope it helps,
Mayank

0
Avatar

subbarao

--subbarao--

1269
| 5 2 8
Chennai, India
--subbarao--


subbarao
4/12/18 0:26

Hello Maks,

Try the following code

@api.multi

@api.onchange('sla_id')

def sla_inheritence(self):

        if self.company_type == 'company':

                if self.child_ids and self.sla_id:

                        for child in self.child_ids:

                                child.sla_id = self.sla_id.id

Realizar una pregunta
Writer
Keep Informed
1 seguidor(es)
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