Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong number of arguments when calling on_change method #49

Open
agrings opened this issue Jan 31, 2018 · 1 comment
Open

Wrong number of arguments when calling on_change method #49

agrings opened this issue Jan 31, 2018 · 1 comment

Comments

@agrings
Copy link

agrings commented Jan 31, 2018

Hello,

Im trying to call the following onchange method:

@api.onchange('fiscal_category_id',
                  'fiscal_position',
                  'invoice_line_tax_id',
                  'quantity',
                  'price_unit',
                  'discount',
                  'insurance_value',
                  'freight_value',
                  'other_costs_value')
    def onchange_fiscal(self):
        ctx = dict(self.env.context)
        if self.invoice_id.type in ('out_invoice', 'out_refund'):
            ctx.update({'type_tax_use': 'sale'})
        else:
            ctx.update({'type_tax_use': 'purchase'})

        partner_id = self.invoice_id.partner_id.id or ctx.get('partner_id')
        company_id = self.invoice_id.company_id.id or ctx.get('company_id')
        if company_id and partner_id and self.fiscal_category_id:
            result = {'value': {}}
            kwargs = {
                'company_id': company_id,
                'partner_id': partner_id,
                'partner_invoice_id': self.invoice_id.partner_id.id,
                'product_id': self.product_id.id,
                'fiscal_category_id': self.fiscal_category_id.id,
                'context': ctx
            }
            result = self.with_context(ctx)._fiscal_position_map(
                result, **kwargs)

            kwargs.update({
                'invoice_line_tax_id': [
                    (6, 0, self.invoice_line_tax_id.ids)],
                'quantity': self.quantity,
                'price_unit': self.price_unit,
                'discount': self.discount,
                'fiscal_position': self.fiscal_position.id,
                'insurance_value': self.insurance_value,
                'freight_value': self.freight_value,
                'other_costs_value': self.other_costs_value,
            })
            result['value'].update(self._validate_taxes(kwargs))
            self.update(result['value'])

So i used the suggestion given in the docs:

def on_change(record, method, args=None, kwargs=None):
    """Update `record` with the result of the on_change `method`"""
    res = record._odoo.execute_kw(record._name, method, args, kwargs)
    for k, v in res['value'].iteritems():
        setattr(record, k, v)

And called the function:

on_change(invoiceLine, 'onchange_fiscal', [],{})

But I'm getting the error:

onchange_fiscal() takes exactly 1 argument (3 given)
@kryskool
Copy link

kryskool commented Feb 9, 2018

Hi @agrings

This project move to the COA umbrella, please open your issue at https://github.com/OCA/odoorpc/

Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants