Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
743 มุมมอง

Hello

I recently added a many2one field (canal_id) to my quotation template and i want to pass the value to my invoice


My code looks like this:

class canal_ventas(models.Model):

    _name = 'canal_ventas.canal_ventas'

    _description = 'Agrega variable canal de ventas a la cotizacion/orden de venta'


    name = fields.Char(string='Nombre canal de ventas', required=True)

    description = fields.Text(string='Descripcion del canal')



class canal_ventas_inherit(models.Model):

    _inherit = 'sale.order'


    canal_id = fields.Many2one('canal_ventas.canal_ventas', string="canal ventas")

 


    def _prepare_invoice(self):

        res = super(canal_ventas_inherit, self)._prepare_invoice()

        res.update({

            'canal_inv': self.canal_id,

            })

        return res

       

class factura_canal(models.Model):

    _inherit = 'account.move'



    canal_inv = fields.Many2one('canal_ventas.canal_ventas', string="canal ventas")

In the quotation form vie I see the new field and i can select values to it.

Also, In the invoice form view I see the new canal_inv field and I can select values on it if a create a new invoice directly in the account.move model.

My problem is when i try to pass the values from a quotation to an invoice. If I open an existing quotation (S0078 for example) and I push the create invoice button, I get the following error:

psycopg2.ProgrammingError: can't adapt type 'canal_ventas.canal_ventas'

Any ideas on how to solve this issue?

By the way I'm using V18

Thank you 

อวตาร
ละทิ้ง
ผู้เขียน

Thank you so much. It's working right now


Great! Would appreciate you marking the answer as correct then :)

คำตอบที่ดีที่สุด

def _prepare_invoice(self):

    res = super(canal_ventas_inherit, self)._prepare_invoice()

    res.update({

        'canal_inv': self.canal_id.id,

    })

    return res

Replace your existing method with this above code. Thanks

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

I'm sorry but I don't know how to do it. its my first time asking for help

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

When writing to a Many2one field, you need to provide the integer value of the record it's supposed to be linked to, not the record object itself.

Hence, this should work:

    def _prepare_invoice(self):
        res = super(canal_ventas_inherit, self)._prepare_invoice()
        res.update({
            'canal_inv': self.canal_id.id,
        })
        return res


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มี.ค. 15
3571
1
ก.ค. 25
231
2
ก.ค. 25
320
1
ก.ค. 25
461
2
ก.ค. 25
494