This question has been flagged
2 Replies
5929 Views

Hello everyone, 

I'm new to the Odoo development and I'm having quite a hard time understanding how inheritance works, or, better said, why inheritance is not working (for me).

The module I'm creating allows to create loyalty cards for customers. So for now I'm creating two very simple models: one of them is the loyalty card itself and the other one is a type of client who has the card. For this last model I'm trying to extend res_partner, which I think is the right call to do it:

class loyaltyCustomer(models.Model):
    _name = 'loyalty.customer'
    _inherit = 'res.partner'
    comment = fields.Text()
    loyaltyCard = fields.Many2one('loyalty.card', String="Tarjeta", required=False)

class loyaltyCard(models.Model):
    _name = 'loyalty.card'
    customer = fields.Many2one('loyalty.customer', String="Cliente")
    barcode = fields.Char(String="", required=True)
    loyaltyAmount = fields.Float()
    returnsAmount = fields.Float()


After creating my views.xml I can create loyalty cards without any issue (I tried first using res_partner directly and it worked perfectly). But the moment I switch to use my custom model, using the same formview as res_partner, I get this error:

Odoo Server Error
Traceback (most recent call last):
[...a lot of lines...]
raise ValueError("Wrong value for %s: %r" % (self, value))
ValueError: Wrong value for loyalty.customer.commercial_partner_id: loyalty.customer(<odoo.models.NewId object at 0x10dde3c50>,)

And I really don't know what to do next to fix it, so any help would be really appreciated.  I'm using Odoo 10.

Avatar
Discard
Best Answer

I got same errors. I simply remove the field has name="commerical_partner_id" from xml view then no error will happen

Avatar
Discard
Best Answer

Hi, 

I think relation between the two models is incorrectly set. Each customer has got one loyalty card right? So you may try like this:

class loyaltyCustomer(models.Model):
    _name = 'loyalty.customer'    
    _inherit = 'res.partner'
    
    comment = fields.Text() loyaltyCard = fields.Many2one('loyalty.card', String="Tarjeta", required=True)
class loyaltyCard(models.Model): _name = 'loyalty.card'
    
    customer = fields.One2many('loyalty.customer','loyaltyCard',String="Cliente") barcode = fields.Char(String="", required=True) loyaltyAmount = fields.Float() returnsAmount = fields.Float()

Here on the customer, you can select a loyalty card, so each customer record is linked to a loyalty card record using the Many2one relation. And on the loyalty card, using the One2many field, I can see the customer linked to this particular loyalty card.

Avatar
Discard