jpozzo
jpozzo

Reputation: 141

irregularity with One2Many field Odoo

I have the following problem I am creating a form that is a budget replica, but this type of budget does not carry VAT% and good will not pass through accounting.

Well the problem is the following I have created a model called budget.table It is the following :

class TableElements(models.Model):
    _name = 'budget.table'
    product_id = fields.Many2one('product.product', string='Product',ondelete='restrict', index=True)
    name = fields.Text(string='Description', required=True)
    quantity = fields.Float(string='Quantity',required=True, default=1)
    price_unit = fields.Float(string='Unit Price', required=True,)
    price_subtotal = fields.Float(string='Amount',store=True, readonly=True)

and I have another model called budget.two which is the following:

class BudgetTwo(models.Model):
    _name = 'budget.two'
    name = fields.Char(string ='Nombre', copy=False, index=True ,default ="Nuevo")
    partner_id =fields.Many2one('res.partner' ,string ='Cliente', copy=False, index=True,required=True)
    deliver_date = fields.Date(string ='Fecha de Entrega')
    expiration_date = fields.Date(string ='Fecha de expiración')
    pay_place =fields.Many2one('account.payment.term' ,string='Plazo de Pago')
    order_line = fields.One2many('budget.table','id' ,string = 'Pedidos' )
    total = fields.Float(string = 'Total:' ,compute="_total")

Well I want: as you can see in 'budget.two' there is a One2Many field which I will add all the new products that in turn will be saved in this type of new budget that I am created as I already commented without VAT and it will not happen by the accounting module.

When I select the products that I am going to save the One2manny, I keep it blank. Example:

So it should be kept: enter image description here

but when you save it, look how it is stored without any element in the One2MAny field:

[![enter code here][2]][2]

Upvotes: 1

Views: 406

Answers (1)

Osama Rashad
Osama Rashad

Reputation: 46

In 'budget.table' add this field:

budget_two_id = fields.Many2one('budget.two')

In 'budget.two' correct this field:

order_line = fields.One2many('budget.table', 'budget_two_id', string='Pedidos')

The point is any One2many field should have an inverse field (Many2one) on the other model as a foreign key.

Upvotes: 2

Related Questions