Skip to Content
Menu
This question has been flagged
2 Replies
1427 Views

Hello,

In order to create multiple sequences for different types of purchase orders, 

I tried overriding a create method in purchase module but getting an error -

return super(new_purchase, self.with_context(company_id=company_id)).create(vals)
TypeError: super(type, obj): obj must be an instance or subtype of type 

My code -

@api.model
def create(self, vals):
company_id = vals.get('company_id', self.default_get(['company_id'])['company_id'])
if vals.get('name', 'New') == 'New':
seq_date = None
if 'date_order' in vals:
seq_date = fields.Datetime.context_timestamp(self, fields.Datetime.to_datetime(vals['date_order']))
vals['name'] = self.env['ir.sequence'].with_context(force_company=company_id).next_by_code('purchase.order', sequence_date=seq_date) or '/'
return super(new_purchase, self.with_context(company_id=company_id)).create(vals)

new_purchase is the name of inherited purchase.order class

How to fix this error?

Thanks in advance!

Avatar
Discard
Author Best Answer

Found problem in my code - there were two classes with the same class name. I changed name of one of them and the error is gone. Thank you!

Avatar
Discard
Best Answer

Hi,

You can inherit the compute_name function of model and add condition (if any) or create new function like below.

@api.depends('variable', 'operator', 'max_value', 'list_base_price', 'list_price', 'variable_factor')
def _compute_name(self):
    for rule in self:
        name = 'if %s %s %s then' % (rule.variable, rule.operator, rule.max_value)
        if rule.list_base_price and not rule.list_price:
            name = '%s fixed price %s' % (name, rule.list_base_price)
        elif rule.list_price and not rule.list_base_price:
            name = '%s %s times %s' % (name, rule.list_price, rule.variable_factor)
        else:
            name = '%s fixed price %s plus %s times %s' % (name, rule.list_base_price, rule.list_price, rule.variable_factor)
        rule.name = name

Regards

Avatar
Discard