El 25/04/2015 2:30, <[email protected]> va escriure:
>
> Hii,
>
>  Iam trying to create an invoice and save it, but later i realized that
each line in an invoice should be saved in order to save the
account.invoice,
>
> hence i tried this code
>
> Invoice = Model.get('account.invoice')
>     InvoiceLine = Model.get('account.invoice.line')
>     invoice = Invoice()
>     invoice.party = party
>     invoice.payment_term = payment_term
>     line = invoice.lines.new()
>     line.product = product
>     line.quantity = 5
>
>
>     account=create_account(company,'revenue','Main Income')
>     account.type=creat_types(company)
>     account.save()
>     # pdb.set_trace()
>     line.account=account#<<----line of error
>     line.save()
>     invoice.lines.append(line)
>
>
>
> but this lead me to this error:
>
>
---------------------------------------------------------------------------
> AssertionError                            Traceback (most recent call
last)
> /usr/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc in
execfile(fname, *where)
>     176             else:
>     177                 filename = fname
> --> 178             __builtin__.execfile(filename, *where)
>
>
> /home/projects/tutorials/invoice_testing.py in <module>()
>     120     account.save()
>     121     # pdb.set_trace()
> --> 122     line.account=account#<<----line of error
>     123     line.save()
>     124     invoice.lines.append(line)
>
>
> /home/projects/tutorials/lib/python2.7/site-packages/proteus/__init__.pyc
in __set__(self, instance, value)
>     258         if value:
>     259             assert value._config == instance._config
> --> 260         super(Many2OneDescriptor, self).__set__(instance, value)
>     261
>     262
>
>
> /home/projects/tutorials/lib/python2.7/site-packages/proteus/__init__.pyc
in __set__(self, instance, value)
>     127         if previous != getattr(instance, self.name):
>     128             instance._changed.add(self.name)
> --> 129             instance._on_change([self.name])
>     130             if instance._parent:
>     131
instance._parent._changed.add(instance._parent_field_name)
>
>
> /home/projects/tutorials/lib/python2.7/site-packages/proteus/__init__.pyc
in _on_change(self, names)
>    1000         if values:
>    1001             context = self._config.context
> -> 1002             changes = getattr(self._proxy, 'on_change')(values,
names, context)
>    1003             for change in changes:
>    1004                 self._set_on_change(change)
>
>
> /home/projects/tutorials/lib/python2.7/site-packages/proteus/config.pyc
in __call__(self, *args)
>     176                 inst = args.pop(0)
>     177                 if hasattr(inst, self._name):
> --> 178                     result = rpc.result(meth(inst, *args,
**kwargs))
>     179                 else:
>     180                     result = [rpc.result(meth(i, *args, **kwargs))
>
>
> /home/projects/tutorials/FSERP/trytond/trytond/model/modelview.pyc in
on_change(self, fieldnames)
>     654             method = getattr(self, 'on_change_%s' % fieldname,
None)
>     655             if method:
> --> 656                 method()
>     657         # XXX remove backward compatibility
>     658         return [self._changed_values]
>
>
> /home/projects/tutorials/FSERP/trytond/trytond/model/modelview.pyc in
wrapper(self, *args, **kwargs)
>      80     def wrapper(self, *args, **kwargs):
>      81         result = func(self, *args, **kwargs)
> ---> 82         assert result is None, func
>      83         return self
>      84     wrapper.on_change = True
>
>
> AssertionError: <unbound method account.invoice.line.on_change_account>
>
>
>
> ---------------------------------------------
> Since iam running the script in ipython i tried to check what is the
value of line.account, it shows the correct account as assigned in the code
at which the error occurred.
> so why did the error occur in the first place?

The problem is in the on_change_account method, not in your proteus code
nor data.
Are you using any custom module?
Are you using the same Tryton serie (3.4, 3.6) for server, modules and
proteus?
Proteus simulates what is done in tryton client, so on_change and
on_chamge_with methods are called. Maybe it's useful to reproduce what you
are trying to domanually in the client.

> and after it quits with an error in interpretter after checking the value
of line.account(which was assigned properly) i tried to append it to the
invoice using invoice.lines.append(line),
> but it showed me this error:

I think it's unnecessary and provably incorrect. The lines.new() method
already "append" the line.
You don't need to save the line and provably it's incorrect because you are
saving a line of an invoice that is not saved.
With this code, the better option is save the invoice after add the lines,
which will also create the lines.
I think you are missing the "invoice type" field, which determines the
account type qllowed (revenue or expenses).

Guillem

Reply via email to