Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
26272 Ansichten

from odoo import models, fields,api, _

import datetime


class RestaurantPemesananBahan(models.Model):

    _name='restaurant.pemesanan_bahan'

    _inherit = ['mail.thread', 'mail.activity.mixin'] #untuk membuat bot chatter / chat history yg dilakukan

    _description = 'Pemesanan Bahan'


    id_cabang = fields.Many2one('restaurant.cabang',string="Cabang")

    id_bahan = fields.One2many('restaurant.pemesanan_bahan_detail', 'id_pemesanan_bahan',string="Bahan", required=True)

    id_vendor = fields.Many2one('restaurant.vendor',string="Vendor")

    total_biaya = fields.Monetary(string="Total Biaya")

    currency_id = fields.Many2one('res.currency', 'Mata Uang',

                                  default=lambda self: self.env.user.company_id.currency_id, readonly=True)

    state = fields.Selection([

        ('menunggu_konfirmasi','Menunggu Konfirmasi'),

        ('konfirmasi','Konfirmasi'),

        ('pengiriman','Pengiriman'),

        ('done','Done'),

        ('cancel','Cancel')

    ],default='menunggu_konfirmasi',string="Status Pemesanan")

    tanggal_pemesanan_bahan = fields.Date(string="Tanggal Pesan",default=datetime.date.today(),readonly=True)


    @api.model

    def default_get(self, fields):

        res = super(RestaurantPemesananBahan, self).default_get(fields)

        cabang = self.env['restaurant.cabang'].search([('user_id', '=', self._uid)],limit=1)  # cari cabang melalui table staff

        res['id_cabang'] = cabang.id

        return res


    # @api.model

    # def create(self,vals_list):

    #     for rec in self:

    #         bahan = rec.env['restaurant.bahan'].search([('vendor_id','=',rec.id_vendor.id)])

    #         for data in bahan:

    #             val = {

    #                 'id_pemesanan_bahan':self.id_bahan.id,

    #                 'bahan_id':data.id,

    #                 'harga':data.harga,

    #                 'jumlah':0,

    #                 'vendor_id':rec.id_vendor.id,

    #                 'currency_id':data.currency_id

    #             }

    #             print("id pemesanan bahan",self.id_bahan.id)

    #             print("id bahan",data.id)

    #             print("harga",data.harga)

    #             print("id vendor",rec.id_vendor.id)

    #

    #             self.env['restaurant.pemesanan_bahan_detail'].create(val)

    def action_konfirmasi(self):

        for rec in self:

            rec.state = 'konfirmasi'

    def action_pengiriman(self):

        for rec in self:

            rec.state = 'pengiriman'

    def action_done(self):

        for rec in self:

            rec.state = 'done'

    def action_cancel(self):

        for rec in self:

            rec.state = 'cancel'


    @api.onchange('id_vendor')

    @api.multi

    def ubah_isi_notebook(self):

        for rec in self:

            bahan = rec.env['restaurant.bahan'].search([('vendor_id','=',rec.id_vendor.id)])

            lines=[(5,0,0)]

            for data in bahan:

                val = {

                    'bahan_id':data.id,

                    'harga':data.harga,

                    'jumlah':0,

                    'vendor_id':rec.id_vendor.id,

                    'currency_id':data.currency_id

                }

                lines.append((0,0,val))

            rec.id_bahan = lines


    @api.onchange('id_bahan')

    def total_harga(self):

        harga = 0

        for rec in self:

            for data in rec.id_bahan:

                harga+=data.harga*data.jumlah

        self.total_biaya = harga


class RestaurantPemesananBahanDetail(models.Model):

    _name='restaurant.pemesanan_bahan_detail'

    _description = 'Pemesanan Bahan Detail'


    bahan_id = fields.Many2one('restaurant.bahan',string="Bahan",required=True)

    harga = fields.Monetary(string="Harga Bahan",required=True)

    jumlah = fields.Integer(string="Jumlah Bahan", default=0,required=True)

    vendor_id = fields.Many2one('restaurant.vendor',string="Vendor",required=True)

    id_pemesanan_bahan = fields.Many2one('restaurant.pemesanan_bahan',string="Pemesanan Bahan",required=True)

    currency_id = fields.Many2one('res.currency', 'Mata Uang',

                                  default=lambda self: self.env.user.company_id.currency_id, readonly=True,required=True)



    @api.onchange('bahan_id')

    def harga_berubah(self):

        harga_baru=0

        nama_vendor = ""

        for rec in self:

            for data in rec.bahan_id:

                harga_baru = data.harga

                nama_vendor = data.vendor_id

        self.harga = harga_baru

        self.vendor_id = nama_vendor

Avatar
Verwerfen
Autor

I have already watched that but i dont know where should i put the create button because it is one2many field. Sorry i am still new

Beste Antwort

Hi,

This error is shown when you haven't supplied value for the required field during creation of some records. You can see an example case here and see how to fix it in your code.

See: How To Fix Mandatory Field is Not Correctly Set Error in Odoo

Thanks

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
1
Sept. 23
3460
2
Juli 20
3766
1
Jan. 23
2577
1
Juni 22
6108
1
Juni 22
3019