<commit_before>﻿##############################################################################
#
#    Copyright (C) 2014-2017 Compassion CH (http://www.compassion.ch)
#    Releasing children from poverty in Jesus' name
#    @author: <NAME> <<EMAIL>>
#
#    The licence is in the file __manifest__.py
#
##############################################################################

from odoo import fields, models, api
import datetime
from dateutil.relativedelta import relativedelta


class InvoicerWizard(models.TransientModel):

    ''' This wizard generate invoices from contract groups when launched.
    By default, all contract groups are used.
    '''
    _name = 'recurring.invoicer.wizard'
    _description = 'Recurring invoicer wizard'

    generation_date = fields.Date(readonly=True)

    @api.multi
    def generate(self):
        date_limit = datetime.date.today() + relativedelta(months=+1)

        recurring_invoicer_obj = self.env['recurring.invoicer']
        contract_groups = self.env['recurring.contract.group'].search([
            ('next_invoice_date', '<=', date_limit),
            ('next_invoice_date', '!=', False)])
<commit_msg>CO-3694 generate invoice based on advanced billing month and not always for one month in advance (#130)<commit_after>﻿##############################################################################
#
#    Copyright (C) 2014-2017 Compassion CH (http://www.compassion.ch)
#    Releasing children from poverty in Jesus' name
#    @author: <NAME> <<EMAIL>>
#
#    The licence is in the file __manifest__.py
#
##############################################################################

from odoo import fields, models, api

class InvoicerWizard(models.TransientModel):
    ''' This wizard generate invoices from contract groups when launched.
    By default, all contract groups are used.
    '''
    _name = 'recurring.invoicer.wizard'
    _description = 'Recurring invoicer wizard'

    generation_date = fields.Date(readonly=True)

    @api.multi
    def generate(self):

        recurring_invoicer_obj = self.env['recurring.invoicer']

        self.env.cr.execute("""
        SELECT id FROM recurring_contract_group
        WHERE
            next_invoice_date IS NOT NULL AND
            next_invoice_date <= now() + interval '1 month' * advance_billing_months;
        """)
        gids = self.env.cr.fetchall()
        contract_groups = self.browse(gids)

{'fraction_non_alphanumeric': 0.22052130740587506, 'fraction_numerical': 0.01034340091021928, 'mean_word_length': 3.9549180327868854, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3015470', 'n_tokens_mistral': 716, 'n_tokens_neox': 652, 'n_words': 174}