Odoo Help


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.


How to get list of invoices based on partner selected and a line item?

on 3/13/14, 3:48 AM 1,252 views

Hi, I have been looking around for a solution that can help me in getting a list of invoices in a drop-down list based on the partner selected and the line item name = 'CD Break', I tried this code but I only get the list of invoices based on the partner and not the line, also I need to use another field for showing the invoices and not the POS number. Please help following is my python code and the xml file:

class new_test(osv.osv):
    _name = 'new.test'    

    def _sel_func(self, cr, uid, context=None):
        obj = self.pool.get('account.invoice')
        ids = obj.search(cr, uid,[],context=context)
        res = obj.read(cr, uid, ids, ['name', 'id'], context)
        res = [(r['id'], r['name']) for r in res]
        return res

    _columns ={
                'partner_id': fields.many2one('res.partner', 'Partner', change_default=True,required=True,),
##                'invoice_id': fields.function(_get_invoices, type='many2one',relation='account.invoice',string="Invoices",store=True,readonly=False),
                'pinvoices': fields.many2one('account.invoice','CD Break Invoice',domain="[('partner_id', '=', partner_id),('invoice_line', 'ilike', 'CD Break')]",selection=_sel_func),
    def remove_penalty(self, cr, uid, ids, context=None):
        res = {}
        name = 'CD Break'
        for penalties in self.browse(cr,uid,ids,context=context):
            if penalties:
                pid = penalties.partner_id.id
                number = penalties.pinvoices.serial_number
                invoice_id = penalties.pinvoices.id
                raise orm.except_orm(_(''), (str(number)))
                cr.execute("DELETE FROM account_invoice_line WHERE name=%s and invoice_id=%s", (name,invoice_id))
                cr.execute("DELETE FROM account_move WHERE name=%s and invoice_id=%s", (name,invoice_id))

        return res



<?xml version="1.0" ?>

        <record id="view_new_test_form" model="ir.ui.view">
            <field name="name">new.test.form</field>
            <field name="model">new.test</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="New test" >
                    <field name="partner_id"/>
                    <!-- <field name="invoice_id"/>  -->
                    <field name="pinvoices" />
                    <separator colspan="4" string="Actions" col="2"/>
                    <button name="remove_penalty" string="Remove Penalty" type="object" icon="gtk-execute"/>
                    <button name="" string="Cancel" type="object" icon="gtk-cancel"/>


        <record model="ir.actions.act_window" id="action_new_test_form">
            <field name="name">New Test</field>
            <field name="res_model">new.test</field>

        <menuitem name="TEST" id="menu_new_test"/>
        <menuitem name="New Test" id="menu_test" parent="new_test.menu_new_test" action="action_new_test_form" sequence="1"/>


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)


Asked: 3/13/14, 3:48 AM
Seen: 1252 times
Last updated: 3/16/15, 8:10 AM