Pass custom field values from oppertunity to quotation in odoo 10

徘徊边缘 提交于 2019-12-08 07:27:52

问题


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!

回答1:


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)



回答2:


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)



回答3:


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 


来源:https://stackoverflow.com/questions/41973852/pass-custom-field-values-from-oppertunity-to-quotation-in-odoo-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!