[TMP] beginning of state of last invoice

This commit is contained in:
michel 2018-02-09 19:44:18 +01:00
parent 30d218c64e
commit c844cf732f

View File

@ -40,12 +40,16 @@ class GolemMember(models.Model):
'default_partner_id': self.partner_id.id}}
# state_invoice = fields.One2many(related='member_id.invoice_ids')
state_last_invoice = fields.Char(compute='_compute_state_of_last_invoice')
# payment_ids = fields.One2many("account.payment","payment_ids")
state_last_invoice = fields.Integer(compute='_compute_state_of_last_invoice')
account_payment_ids = fields.One2many('account.payment', 'partner_id')
@api.depends('invoice_ids')
def _compute_state_of_last_invoice(self):
for member in self:
state = member.invoice_ids.filtered(lambda inv: inv.state in ('open', 'paid'))
sorted_date = state.sorted(key=lambda r: r.date_invoice)
member.state_last_invoice = sorted_date[-1]
state_invoice = member.invoice_ids.filtered(lambda inv: inv.state in ('open', 'paid'))
date_state_invoice = state_invoice.sorted(key=lambda r: r.date_invoice, reverse=True)
state_payment = member.account_payment_ids.filtered(lambda inv: inv.state in ('open', 'paid'))
date_state_payment = state_payment.sorted(key=lambda r: r.write_date, reverse=True)
member.state_last_invoice = date_state_invoice[0]