I am working on a module for bonuses for the quantity of products sold,
and doing so I have run into the following error that I don't know how to solve:
Expected singleton: sale.bonds (1, 2)
I am trying to put bonuses for many products and I get the error.
my py:class SaleBounty(models.Model):
_name = 'sale.bonds'
_description = 'Bonos'
bond_line = fields.Many2one('product.brand')
product_id = fields.Many2one('product.product', 'Product', required=True)
qty = fields.Integer(string='qty', required=False)
bond = fields.Integer(string='Bono', required=False)
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
bond_price = fields.Float(string='P. Bono',
compute='bonds_compute', default=0.0)
@api.multi
@api.depends('product_uom_qty')
def bonds_compute(self):
for rec in self:
if rec.product_uom_qty == rec.product_id.product_brand_id.bonds_id.qty:
rec.bond_price = rec.product_id.product_brand_id.bonds_id.bond / \
rec.product_id.product_brand_id.bonds_id.qty
thanks!!
Hi,
bonds_id field in the rec.product_id.product_brand_id.bonds_id.qty is a many2many or one2many field ?
Hi Gerson Carranza,
This happen because your field is many2many or one2many, where you can hold more that on record. So, try to run the loop upto it. So, that it can get all the values .
Hi, is a One2many, here is all code
class BrandBounty(models.Model):
_inherit = 'product.brand'
bonds_id = fields.One2many('sale.bonds', 'bond_line', string='Bonos')
class SaleBounty(models.Model):
_name = 'sale.bonds'
_description = 'Bonos'
bond_line = fields.Many2one('product.brand')
product_id = fields.Many2one('product.product', 'Product', required=True)
qty = fields.Integer(string='qty', required=False)
bond = fields.Integer(string='Bono', required=False)
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
bond_price = fields.Float(string='P. Bono',
compute='bonds_compute', default=0.0)
@api.multi
@api.depends('product_uom_qty')
def bonds_compute(self):
for rec in self:
if rec.product_uom_qty == rec.product_id.product_brand_id.bonds_id.qty:
rec.bond_price = rec.product_id.product_brand_id.bonds_id.bond / \
rec.product_id.product_brand_id.bonds_id.qty