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
new_test()
XML:
<?xml version="1.0" ?>
<openerp>
<data>
<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"/>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_new_test_form">
<field name="name">New Test</field>
<field name="res_model">new.test</field>
</record>
<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"/>
</data>
</openerp>