Pass custom field values from oppertunity to quota

2019-05-30 14:38发布

I have added a custom field in opportunity and same field in quotation and I want to add value in that custom field in opportunity and pass that values to Quotation in same field.

In odoo 8 it was done by overriding makeOrder method but now in odoo 10 I have no idea how to do it.

Someone please help me about it. Thanks!

3条回答
Ridiculous、
2楼-- · 2019-05-30 15:09

I found this solution, It is working well for me.

@api.onchange('opportunity_id')
    def _get_description(self):
        if self.opportunity_id.id:
            self.x_description = self.opportunity_id.x_description 
查看更多
贼婆χ
3楼-- · 2019-05-30 15:12

When you write your field definitions, you can solve it. It will be change on the fly, if you set 'store' property to True, then it will write it to the db, so this will equivalent with your solution. If I know well, my way is faster, and this is the right way. More transparent code management.

opportunity_id = fields.Many2One('opportunity', string='Opportunity')
x_description = fields.Text(related='opportunity_id.x_description', store=True)
查看更多
叛逆
4楼-- · 2019-05-30 15:16

thank you it also the thing I have struggled for few weeks. Mine is below (to transfer a value commission set under "res.company" to be used in model "sale.order": ( I didn't known "company_it" is fields of relationship)

class YourCompany(models.Model):
    _inherit = "res.company"

    company_commission =  fields.Float( default =15.00)
    commission_ids = fields.One2many( 'sale.order', 'company_id', 
        string="Commission_ids")

class SaleOrder(models.Model):
    _inherit = "sale.order"
    company_id = fields.Many2one('res.company', string='company_id', 
          required=True)
    company_commission = 
                fields.Float(related='company_id.company_commission', 
         string="Comm", store = True)
查看更多
登录 后发表回答