Skip to content

Instantly share code, notes, and snippets.

@holdenrehg
Last active June 4, 2016 02:15
Show Gist options
  • Save holdenrehg/54b2fe11f71158b3fa33558246bf8822 to your computer and use it in GitHub Desktop.
Save holdenrehg/54b2fe11f71158b3fa33558246bf8822 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import logging
from datetime import datetime
from openerp import api, fields, models, tools
_logger = logging.getLogger(__name__)
LATE_LIMIT = 25
class AccountInvoice(models.Model):
_inherit = 'account.invoice'
is_late = fields.Boolean('Is Late', compute='compute_is_late')
@api.multi
@api.depends('date_invoice')
def compute_is_late(self):
"""
Computes if this bill is late. The bill is late if it has
been the LATE_LIMIT days past the invoice date.
"""
for invoice in self:
_logger.info('DEPENDS_TEST: computing is late on invoice id ' + str(invoice.id))
if invoice.date_invoice:
date_invoice = datetime.strptime(invoice.date_invoice, tools.DEFAULT_SERVER_DATE_FORMAT)
now = datetime.strptime(datetime.strftime(datetime.today(), tools.DEFAULT_SERVER_DATE_FORMAT), tools.DEFAULT_SERVER_DATE_FORMAT)
invoice.is_late = (now - date_invoice).days > LATE_LIMIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment