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

create quotation or invoices? #39

Closed
ericmachine88 opened this issue Jun 14, 2014 · 8 comments
Closed

create quotation or invoices? #39

ericmachine88 opened this issue Jun 14, 2014 · 8 comments
Labels

Comments

@ericmachine88
Copy link

Like to check how much I could do with erppeek? Is it production ready?

Can I create a new draft quotation, then send for approval, etc?

Same to invoices creation?

Any help? Thanks.

@florentx
Copy link
Member

With ERPpeek, you have the same capacity as the web client. So you can technically create OpenERP objects, trigger workflow actions, etc...

However you have to figure out the correct arguments, and you need to apply the onchange actions manually when you need them.

If you want to emulate the web client, you can activate the logging level DEBUG_RPC in OpenERP and observe the chain of RPC requests when doing the action in the web client.
Then you can write the ERPpeek script to repeat these actions.

In ERPpeek you can also trace the chain of RPC requests/responses with the switch -v or -vv.

@florentx
Copy link
Member

The issue #15 contains an example of such usage: create a test invoice with an on_change action in OpenERP 6.1.

@ericmachine88
Copy link
Author

Hi florentx,

I have tried to migrate this to v7. But I am having some problems here.

#!/usr/bin/env python
from __future__ import print_function
import erppeek
import time
from datetime import date

client = erppeek.Client.from_config('demo4')

# create a partner
#client.model('res.partner').create({'name' : 'eric machine corp'})

# find a partner 
proxy = client.model('res.partner')
partners = proxy.browse([])
for partner in partners:
    print("{partner.id} {partner.name}".format(partner=partner))
print(partners[3])  
partner = partners[3] # i can't figure out what's the best way to get "eric machine corp"

account_invoice_obj = client.model('account.invoice')

data = {
    'name' : "Invoice # 1",
    'type' : "out_invoice",
    'address_invoice_id' : partner.address[0].id,
    'partner_id' : partner.id
}

rv = account_invoice_obj.onchange_partner_id([], 'out_invoice', partner.id, date.today(), False, False)

data.update(rv['value'])
inv = account_invoice_obj.create(data)

if partner.contract_ids:
    inv.write({'contract_id': partner.contract_ids[0].id})

Questions:-

a) What is the best way to get the partner for "eric machine corp"?

b) I have an error on this code

Traceback (most recent call last):
  File "create-invoice.py", line 31, in <module>
    'address_invoice_id' : partner.address[0].id,
TypeError: 'instancemethod' object has no attribute '__getitem__'

c) When I disable that line of code above and try to run again, I got another error

Traceback (most recent call last):
  File "create-invoice.py", line 35, in <module>
    rv = account_invoice_obj.onchange_partner_id([], 'out_invoice', partner.id, date.today(), False, False)
  File "/Library/Python/2.7/site-packages/erppeek.py", line 1121, in wrapper
    return self._execute(attr, *params, **kwargs)
  File "/Library/Python/2.7/site-packages/erppeek.py", line 666, in execute
    res = self._execute(obj, method, *params)
  File "/Library/Python/2.7/site-packages/erppeek.py", line 369, in <lambda>
    wrapper = lambda s, *args: s._dispatch(name, args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1572, in __request
    allow_none=self.__allow_none)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1085, in dumps
    data = m.dumps(params)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 632, in dumps
    dump(v, write)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 646, in __dump
    raise TypeError, "cannot marshal %s objects" % type(value)
TypeError: cannot marshal <type 'datetime.date'> objects

Any tips to write this code better on v7? Thanks.

@florentx
Copy link
Member

Even if I don't use 7.0 I'll try to give you some hints.

a) you can use an OpenERP domain to select the correct partner

partner1 = model('res.partner').get(['name = eric machine corp'])

# or one of these alternatives
partner2 = model('res.partner').get(['name like eric machine'])
partner3 = model('res.partner').get([('name', '=', 'eric machine corp')])
partner3 = model('res.partner').get([('name', 'like', 'eric machine')])

b) the columns on res.partner are not the same across versions. You can inspect the models to identify which fields you want to fill.
IIRC correctly the res.partner is used both for Partners and Contact addresses in 7.0...

>>> print model('res.partner').keys()
>>> model('res.partner').field('child_ids')
{'context': {},
 'domain': [('active', '=', True)],
 'relation': 'res.partner',
 'relation_field': 'parent_id',
 'selectable': True,
 'string': 'Contacts',
 'type': 'one2many'}
>>> model('res.partner').field('type')
{'help': 'Used to select automatically the right address according to the context in sales and purchases documents.',
 'selectable': True,
 'selection': [('default', 'Default'),
               ('invoice', 'Invoice'),
               ('delivery', 'Shipping'),
               ('contact', 'Contact'),
               ('other', 'Other')],
 'string': 'Address Type',
 'type': 'selection'}

And you can do a similar analysis on the account.invoice model.

c) the command should be changed to cast the <datetime.date> object to a string

... str(date.today())

@ericmachine88
Copy link
Author

Thanks for coming back.

2 questions.

I have tried to run this command here

my db = demo4

demo4 >>> print model('account.invoice').keys()
['account_id', 'amount_tax', 'amount_total', 'amount_untaxed', 'check_total', 'comment', 'commercial_partner_id', 'company_id', 'currency_id', 'date_due', 'date_invoice', 'fiscal_position', 'internal_number', 'invoice_line', 'journal_id', 'message_follower_ids', 'message_ids', 'message_is_follower', 'message_summary', 'message_unread', 'move_id', 'move_lines', 'move_name', 'name', 'number', 'origin', 'partner_bank_id', 'partner_id', 'payment_ids', 'payment_term', 'paypal_url', 'period_id', 'portal_payment_options', 'reconciled', 'reference', 'reference_type', 'residual', 'sent', 'state', 'supplier_invoice_number', 'tax_line', 'type', 'user_id']

The only thing I can think of that is related to partner is commercial_partner_id

Which I tried to drill deeper

demo4 >>> model('account.invoice').field('commercial_partner_id')
{'context': {},
 'digits': [16, 2],
 'domain': [],
 'fnct_inv': '_fnct_write',
 'fnct_inv_arg': ['partner_id', 'commercial_partner_id'],
 'fnct_search': '_fnct_search',
 'function': '_fnct_read',
 'help': 'The commercial entity that will be used on Journal Entries for this invoice',
 'readonly': True,
 'relation': 'res.partner',
 'selectable': True,
 'store': True,
 'string': 'Commercial Entity',
 'type': 'many2one'}

But I still has no clue what would be the best replacement for

'address_invoice_id' : partner.address[0].id,

in Odoo 7.

  1. Since I can't figure out the solution above, I disable the address_invoice_id in the code, and also followed your advices on the str(date.today()). Now I get another error.
Traceback (most recent call last):
  File "create-invoice.py", line 40, in <module>
    inv = account_invoice_obj.create(data)
  File "/Library/Python/2.7/site-packages/erppeek.py", line 1047, in create
    new_id = self._execute('create', values, context=context)
  File "/Library/Python/2.7/site-packages/erppeek.py", line 666, in execute
    res = self._execute(obj, method, *params)
  File "/Library/Python/2.7/site-packages/erppeek.py", line 369, in <lambda>
    wrapper = lambda s, *args: s._dispatch(name, args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1578, in __request
    verbose=self.__verbose
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1264, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1297, in single_request
    return self.parse_response(response)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1473, in parse_response
    return u.close()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 793, in close
    raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault warning -- Integrity Error

The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set

\[object with reference: currency_id - currency.id]: ''>

Any tips? Thanks.

@florentx
Copy link
Member

For the case 1), I guess that you need

    'partner_id': partner.id,

instead of

    'address_invoice_id' : partner.address[0].id,

For 2), the message says it clearly a mandatory field is not correctly set and [object with reference: currency_id - currency.id].
So it means you need to lookup and set the currency of the invoice.

For additional questions, I suggest that you try the mainstream communication channels, because your questions are not specific to ERPpeek, (and I am not a user of OpenERP 7).
https://www.odoo.com/page/community (great links: Help/Forum, Documentation, Developer Memento and IRC channel)

@opmaurya1995
Copy link

Integrity Error

The operation cannot be completed, probably due to the following:

  • deletion: you may be trying to delete a record while other records still reference it
  • creation/update: a mandatory field is not correctly set

[object with reference: y1= - y1=]

@opmaurya1995
Copy link

Please help me
thanks in advance

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

No branches or pull requests

3 participants