Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7706133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:02:35+00:00 2026-06-01T00:02:35+00:00

i dont know if i should be asking this here (im now thinking maybe

  • 0

i dont know if i should be asking this here (im now thinking maybe a moderator would move it to stackoverflow), but im not getting an answer on the openerp or launchpad forums.
In OpenERP 6.0.1, the following function does what its supposed to do when a button is placed in the invoice form to execute it:

class account_invoice(osv.osv):
    _inherit = "account.invoice"

    """ Function to update all lines on invoice """
    def update_invoice(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        line_obj = self.pool.get('account.invoice.line')
        invoice_ids = self.browse(cr, uid, ids, context)
        for invoice in invoice_ids:
            for line in invoice.invoice_line:
                if line.product_id:
                    res = line_obj.product_id_change(cr, uid, [line.id], (line.product_id and line.product_id.id or False), uom=(line.uos_id and line.uos_id.id or False), qty=(line.quantity or 0),
                name=(line.name or ''), type=(invoice.type or False), partner_id=invoice.partner_id.id, fposition_id=invoice.fiscal_position.id, price_unit=(line.price_unit or 0),
                address_invoice_id=(invoice.address_invoice_id and invoice.address_invoice_id.id or False), currency_id=(invoice.currency_id and invoice.currency_id.id or False), context=context)
                    price_unit = res['value']['price_unit']
                    discount = res['value']['discount']
                    line_obj.write(cr, uid, [line.id], {'price_unit': price_unit})
                    line_obj.write(cr, uid, [line.id], {'discount': discount})
        return True

    account_invoice()

this is to say that the invoice lines’ price unit and discount are updated when this button is clicked in the form.

im trying to create a server action for object “Invoice” of type “python code” that executes this function on all invoices from a menu item. in the python code box, i wrote:

inv = self.pool.get('account.invoice')
line_obj = self.pool.get('account.invoice.line')
for invoice in inv.browse(cr, uid, ids):
    for line in invoice.invoice_line:
        res = line_obj.product_id_change(cr, uid, [line.id], (line.product_id and line.product_id.id or False), uom=(line.uos_id and line.uos_id.id or False), qty=(line.quantity or 0), name=(line.name or ''), type=(invoice.type or False), partner_id=invoice.partner_id.id, fposition_id=invoice.fiscal_position.id, price_unit=(line.price_unit or 0), address_invoice_id=(invoice.address_invoice_id and invoice.address_invoice_id.id or False), currency_id=(invoice.currency_id and invoice.currency_id.id or False), context=context)
    price_unit = res['value']['price_unit']
    discount = res['value']['discount']
    line_obj.write(cr, uid, [line.id], {'price_unit': price_unit})
    line_obj.write(cr, uid, [line.id], {'discount': discount})

but it does not work. what am i doing wrong?

EDIT:
can anyone help me write a function that updates all invoices’ lines’ similar to those in /account/wizard/account_invoice_state.py ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:02:37+00:00Added an answer on June 1, 2026 at 12:02 am

    i managed to successfully write what i need, here it is:

    class account_invoice_update(osv.osv_memory):
    
    _name = "account.invoice.update"
    
    """ Function to update all lines on selected invoice(s) """
    def invoice_update(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
    
        pool_obj = pooler.get_pool(cr.dbname)
        data_inv = pool_obj.get('account.invoice').read(cr, uid, context['active_ids'], ['state'], context=context)
    
        for record in data_inv:
            if record['state'] in ('cancel','paid','open'):
                raise osv.except_osv(_('Warning'), _("Selected Invoice(s) cannot be cancelled as they are already in 'Cancelled','Done', or 'Open' state!"))
    
        inv_obj = self.pool.get('account.invoice')
        inv_line_obj = self.pool.get('account.invoice.line')
        for invoice in inv_obj.browse(cr, uid, context.get('active_ids'), context=context):
            for line in invoice.invoice_line:
                res = inv_line_obj.product_id_change(cr, uid, [line.id], (line.product_id and line.product_id.id or False), uom=(line.uos_id and line.uos_id.id or False), qty=(line.quantity or 0), name=(line.name or ''), type=(invoice.type or False), partner_id=invoice.partner_id.id, fposition_id=invoice.fiscal_position.id, price_unit=(line.price_unit or 0), address_invoice_id=(invoice.address_invoice_id and invoice.address_invoice_id.id or False), currency_id=(invoice.currency_id and invoice.currency_id.id or False), context=context)
                price_unit = res['value']['price_unit']
                discount = res['value']['discount']
                inv_line_obj.write(cr, uid, [line.id], {'price_unit': price_unit})
                inv_line_obj.write(cr, uid, [line.id], {'discount': discount})
    
        return {'type': 'ir.actions.act_window_close'}
    
    account_invoice_update()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this as a homework question and dont know how I should go
This should be very easy but I don't know how to do it. I
I don't know if its right place to ask this question or not, but
I'm asking here not because I never used visual studio but because I'm starting
This might seem like a silly question, but after asking some questions on stackoverflow
I'm asking this because I really don't know where I should handle events of
I dont know if I should use the httpcontext caching or the Enterprise Library
( I don't know whether should I also post this question to ServerFault, since
I don't know which title I should use for this question. I have a
This should really be easy for an experienced android programmer. Unfortunately I don't know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.