Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to generate new draft invoice ( invoice_line ) from new generate module?

By
abdul aziz yaakup
on 5/29/14, 5:51 AM 2,276 views

Hi all,

I create a new module to calculate water consumption and I want to generate a new invoice from it. This module has similar models like "sale.order" and "sale.order.line". 

I can generate a draft invoice from my module but the problem is, it doesn't include the invoice_lines. This draft invoice only get the value for the customer (partner_id) , journal (journal_id) and account (account_id).  

Can anyone assist me on this?

Thank you.

 

0
Mariusz Mizgier
On 5/29/14, 6:33 AM

Go to sale/wizard/sale_make_invoice.py and sale/wizard/sale_line_invoice.py for reference - you have methods written right there. Look also at sale.py, especially at _prepare_order_line_invoice_line for further answers.

0
abdul aziz yaakup
On 6/2/14, 9:10 AM

Hi Mariusz Mizgier, Thanks for your tips. I already create the same methods in order to make it happen but I got the following error.

 

2014-06-02 12:52:21,945 5460 ERROR ccsb2 openerp.sql_db: Programming error: can't adapt type 'browse_record', in query insert into "account_invoice" (id,"origin","comment","check_total","reference","payment_term","journal_id","currency_id","partner_id","fiscal_position","user_id","reference_type","company_id","state","type","internal_number","account_id","reconciled","section_id","date_invoice","name","sent",create_uid,create_date,write_uid,write_date) values (31,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,(now() at time zone 'UTC'),%s,(now() at time zone 'UTC')) 2014-06-02 12:52:21,946 5460 ERROR ccsb2 openerp.osv.osv: Uncaught exception Traceback (most recent call last): File "/opt/openerp/v7/server/openerp/osv/osv.py", line 132, in wrapper return f(self, dbname, *args, **kwargs) File "/opt/openerp/v7/server/openerp/osv/osv.py", line 199, in execute res = self.execute_cr(cr, uid, obj, method, *args, **kw) File "/opt/openerp/v7/addons/audittrail/audittrail.py", line 514, in execute_cr return fct_src(cr, uid, model, method, *args, **kw) File "/opt/openerp/v7/server/openerp/osv/osv.py", line 187, in execute_cr return getattr(object, method)(cr, uid, *args, **kw) File "/opt/openerp/v7/extra_addons/utility_meter/wizard/water_make_invoice_advance.py", line 176, in create_invoices res = utility_meter_obj.action_invoice_create(cr, uid, utility_meter_ids, context) File "/opt/openerp/v7/extra_addons/utility_meter/water_meter.py", line 982, in action_invoice_create res = self._make_invoice(cr, uid, val[0][0], reduce(lambda x, y: x + y, [l for o, l in val], []), context=context) File "/opt/openerp/v7/extra_addons/utility_meter/water_meter.py", line 902, in _make_invoice inv_id = inv_obj.create(cr, uid, inv, context=context) File "/opt/openerp/v7/addons/mail/mail_thread.py", line 241, in create thread_id = super(mail_thread, self).create(cr, uid, values, context=context) File "/opt/openerp/v7/server/openerp/osv/orm.py", line 4511, in create cr.execute('insert into "'+self._table+'" (id'+upd0+") values ("+str(id_new)+upd1+')', tuple(upd2)) File "/opt/openerp/v7/server/openerp/sql_db.py", line 161, in wrapper return f(self, *args, **kwargs) File "/opt/openerp/v7/server/openerp/sql_db.py", line 226, in execute res = self._obj.execute(query, params) ProgrammingError: can't adapt type 'browse_record' 2014-06-02 12:52:21,952 5460 ERROR ccsb2 openerp.netsvc: can't adapt type 'browse_record' Traceback (most recent call last): File "/opt/openerp/v7/server/openerp/netsvc.py", line 296, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "/opt/openerp/v7/server/openerp/service/web_services.py", line 626, in dispatch res = fn(db, uid, *params) File "/opt/openerp/v7/server/openerp/osv/osv.py", line 190, in execute_kw return self.execute(db, uid, obj, method, *args, **kw or {}) File "/opt/openerp/v7/server/openerp/osv/osv.py", line 132, in wrapper return f(self, dbname, *args, **kwargs) File "/opt/openerp/v7/server/openerp/osv/osv.py", line 199, in execute res = self.execute_cr(cr, uid, obj, method, *args, **kw) File "/opt/openerp/v7/addons/audittrail/audittrail.py", line 514, in execute_cr return fct_src(cr, uid, model, method, *args, **kw) File "/opt/openerp/v7/server/openerp/osv/osv.py", line 187, in execute_cr return getattr(object, method)(cr, uid, *args, **kw) File "/opt/openerp/v7/extra_addons/utility_meter/wizard/water_make_invoice_advance.py", line 176, in create_invoices res = utility_meter_obj.action_invoice_create(cr, uid, utility_meter_ids, context) File "/opt/openerp/v7/extra_addons/utility_meter/water_meter.py", line 982, in action_invoice_create res = self._make_invoice(cr, uid, val[0][0], reduce(lambda x, y: x + y, [l for o, l in val], []), context=context) File "/opt/openerp/v7/extra_addons/utility_meter/water_meter.py", line 902, in _make_invoice inv_id = inv_obj.create(cr, uid, inv, context=context) File "/opt/openerp/v7/addons/mail/mail_thread.py", line 241, in create thread_id = super(mail_thread, self).create(cr, uid, values, context=context) File "/opt/openerp/v7/server/openerp/osv/orm.py", line 4511, in create cr.execute('insert into "'+self._table+'" (id'+upd0+") values ("+str(id_new)+upd1+')', tuple(upd2)) File "/opt/openerp/v7/server/openerp/sql_db.py", line 161, in wrapper return f(self, *args, **kwargs) File "/opt/openerp/v7/server/openerp/sql_db.py", line 226, in execute res = self._obj.execute(query, params) ProgrammingError: can't adapt type 'browse_record'

 

I hope that you can help me on this because I was stuck at this error. Thanks.

Please copy your code here, so that I can say anything about it. I would be interested in the way you create a dictionary to pass the values for invoice creation.

Currenda Sp. z o.o., Mariusz Mizgier
on 6/2/14, 1:19 PM

Here is my code. def _prepare_invoice(self, cr, uid, order, lines, context=None): if context is None: context = {} pa=1 pb=3 # pc=8 import pdb; pdb.set_trace(); invoice_vals = { 'name': order.client_order_ref or '', 'origin': order.name, 'type': 'out_invoice', 'reference':order.client_order_ref or order.name, 'account_id': order.partner_id.property_account_receivable.id, 'partner_id': order.partner_id.id, 'journal_id': order.journal_id, 'invoice_line': [(6, 0, lines)], 'currency_id': order.currency_id, 'comment': order.note, 'payment_term': order.payment_term and order.payment_term.id or False, 'fiscal_position': order.fiscal_position.id or order.partner_id.property_account_position.id, 'date_invoice': context.get('date_invoice', False), 'company_id': pa, 'user_id': order.user_id and order.user_id.id or False } import pdb; pdb.set_trace(); invoice_vals.update(self._inv_get(cr, uid, order, context=context)) return invoice_vals Here is for the _prepare_line.. def _prepare_invoice_line(self, cr, uid, line, account_id=False, context=None): res = {} if not line.invoiced: if not account_id: if line.product_id: account_id = line.product_id.property_account_income.id if not account_id: account_id = line.product_id.categ_id.property_account_income_categ.id if not account_id: raise osv.except_osv(_('Error!'), _('Please define income account for this product: "%s" (id:%d).') % \ (line.product_id.name, line.product_id.id,)) else: prop = self.pool.get('ir.property').get(cr, uid, 'property_account_income_categ', 'product.category', context=context) account_id = prop and prop.id or False uosqty = self._get_line_qty(cr, uid, line, context=context) uos_id = self._get_line_uom(cr, uid, line, context=context) pu = 0.0 import pdb; pdb.set_trace(); if not account_id: raise osv.except_osv(_('Error!'), _('There is no Fiscal Position defined or Income category account defined for default properties of Product categories.')) res = { 'name': line.name, 'sequence': line.sequence, 'origin': line.order_id.name, 'account_id': line.product_id.property_account_income.id, #'account_id': acc, 'price_unit': pu, 'quantity': uosqty, 'discount': line.discount, 'uos_id': uos_id, 'product_id': line.product_id.id or False, 'account_analytic_id': line.order_id.project_id and line.order_id.project_id.id or False, } return res

abdul aziz yaakup
on 6/2/14, 2:28 PM

Well, surely there is an error in invoice_vals definition - because the code is not clear to read in such message (best would be py file), i can see anyways that you reference 'journal_id': order.journal_id, whereas you should go for order.journal_id.id, as well as 'currency_id': order.currency_id, where it should be order.currency_id.id - both are many2one relations so you need ids of these (that's why error was about browse_record - you wanted to create an object with value of browse_record,id instead of id - that is how is order.journal_id seen in Python). Feel free to ask any further questions, hopefully I will be able to help you. If you need more simple way to create invoice, refer to https://github.com/odoo/odoo/blob/saas-5/addons/account_analytic_analysis/account_analytic_analysis.py lines 665-733.

Currenda Sp. z o.o., Mariusz Mizgier
on 6/2/14, 2:55 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/29/14, 5:51 AM
Seen: 2276 times
Last updated: 3/16/15, 8:10 AM