I have a model (account.invoice) with one2many field (containing unreconciled payments for the same parter as the invoice). This field is viewd as a treeview inside the invoice form. I created a object button for each line in the treeview called reconciliate_payment.
When the button method is called, the payment(account.move.line) is passed in the self argument, but I am missing a reference to the invoice so I can manually reconciliate the payment with the invoice.
(I'm using odoo 8 so I don't have the outstanding credits functionality)
class AccountInvoice(models.Model):
_inherit = 'account.invoice' _name = 'account.invoice'
unreconciled_payment_id = fields.Many2many('account.move.line', string='Entry Lines',compute='_compute_unreconciled_payment_id')
@api.one
def _compute_unreconciled_payment_id(self):
unreconciled_lines = self.env['account.move.line']
domain = [('account_id', '=', self.account_id.id),('partner_id','=',self.env['res.partner']._find_accounting_partner(self.partner_id).id),('reconcile_id','=',False)] self.unreconciled_payment_id=unreconciled_lines.search(domain)
class account_move_line(models.Model):
_inherit = 'account.move.line' name = 'account.move.line'
def reconcilate_payment(self, cr, uid, ids, context=None):
if not ids: return []
line = self.browse(cr, uid, ids[0], context=context)
# invoice = ?