İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
748 Görünümler

Hello from Germany :D

I'm trying to create my first Odoo model.

Create works and write does not work.

Thank you for your help!


from odoo import models, api


class PurchaseOrder(models.Model):

    _inherit = 'purchase.order'

    def button_confirm(self):

        res = super().button_confirm()


        for bestellung in self:

            lieferant = bestellung.partner_id


            for zeile in bestellung.order_line:

                produkt = zeile.product_id

                preis = zeile.price_unit

                waehrung = zeile.currency_id



                vorhandene_info = self.env['product.supplierinfo'].search([

                                                                            ('product_tmpl_id', '=', produkt.product_tmpl_id.id,),

                                                                            ('partner_id', '=', lieferant.id),

                                                                            ], limit=1)


                if vorhandene_info:

                    angebot = self.env['product.supplierinfo'].browse(vorhandene_info.id)

                    angebot.write({

                                    'price': preis,

                                    })

                else:

                    self.env['product.supplierinfo'].create({

                                                                'partner_id': lieferant.id,

                                                                'product_tmpl_id': produkt.product_tmpl_id.id,

                                                                'price': preis,

                                                                'min_qty': 1.0,

                                                                'currency_id':waehrung.id,

                                                                'delay':0

                                                            })

        self.flush()

        return res




Avatar
Vazgeç
En İyi Yanıt

Hi,

Please refer to the code below:


from odoo import models


class PurchaseOrder(models.Model):

    _inherit = 'purchase.order'


    def button_confirm(self):

        res = super().button_confirm()

        for bestellung in self:

            lieferant = bestellung.partner_id


            for zeile in bestellung.order_line:

                produkt = zeile.product_id

                preis = zeile.price_unit

                waehrung = zeile.currency_id

                vorhandene_info = self.env['product.supplierinfo'].search([

                    ('product_tmpl_id', '=', produkt.product_tmpl_id.id),

                    ('partner_id', '=', lieferant.id),

                ], limit=1)

                if vorhandene_info:

                    vorhandene_info.write({'price': preis})

                else:

                    self.env['product.supplierinfo'].create({

                        'partner_id': lieferant.id,

                        'product_tmpl_id': produkt.product_tmpl_id.id,

                        'price': preis,

                        'min_qty': 1.0,

                        'currency_id': waehrung.id,

                        'delay': 0

                    })

        return res


Hope it helps.

Avatar
Vazgeç
Üretici En İyi Yanıt

Thank you !

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Kas 24
12325
2
Ara 23
2377
6
Tem 20
4299
1
Nis 25
3979
2
May 20
6332