Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
4311 Vizualizări

I want to automatically fill in the fields of the 'payment' model with the values from the fields 'customer_name', 'order_item' and 'order_price' in the 'orders' model.

Beginner. Please help

class payment(models.Model):
    _name='pickabite.payment'
    _rec_name='bill_id'
   
    #generating bill_id
    bill_id=fields.Char(string='Bill Id', readonly=True)
    @api.model
    def create(self, vals):
        x = self.env['ir.sequence'].next_by_code('pickabite.payment') or '/'
        vals['bill_id'] = x
        return super(payment,self).create(vals)
    

class orders(models.Model):
    _name='pickabite.orders'
    _rec_name='order_id'
    customer_name=fields.Many2one('pickabite.customer',
            string='Customer Name',required=True)
   

#generating order_id
    order_id = fields.Char(string='Order Id', Translate= True ,
            readonly = True)
    @api.model
    def create(self, vals):
        x = self.env['ir.sequence'].next_by_code('pickabite.orders') or '/'
        vals['order_id'] = x
        return super(orders, self).create(vals)

order_item=fields.One2many('pickabite.order_line','order_code',
            string='Order Item', ondelete='cascade')

order_price=fields.Float(compute='calc_order_price' ,string='Total')
    def calc_order_price(self):
         ..........

Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

Seems you are looking to fetch the details of the model pickabite.orders to the model pickabite.payment , but checking the given part of the code, can't see what is the relation between these two models.


If there is a relation between these two models we can easily do what you are looking for. Can you update the question with the relationship with these two models?

Suppose if you are button click calls the function below,

@api.multi
def button_click(self):
for rec in self:
val = self.env['model_to_search'].search([('field', '=', some_value)])

Like the above bit of the code, you can fetch the values from the other model.

Thanks

Imagine profil
Abandonează