<commit_before># -*- coding: utf-8 -*-

from openerp.osv import orm, fields
from openerp.tools.translate import _


class consolidator(orm.TransientModel):
    _name = "consolidated.invoice.consolidation"
    _description = "Automatic Invoice Consolidation"


    _columns = {
        'partner_id': fields.many2one('res.partner', 'Partner', change_default=True, readonly=True, required=True),
        'method': fields.selection([
            ('po', 'By Purchase Order Number'),
            ('po_for_selection', 'By Purchase Order Number on selected invoices'),
            ('period', 'By Period'),
            ('po_and_period', 'By Purchase Order Number and Period'),
        ], 'Method', help='Consolidate your invoices by...', required=True), # FIXME: add proper help text.
        'period': fields.selection([
            ('daily', 'Daily'),
            ('weekly', 'Weekly'),
            ('monthly', 'Monthly'),
            ('endofmonth', 'Monthly - End of month'),
        ], 'Period', help=''),
        'dayofweek': fields.selection([
            ('monday', 'Monday'),
            ('tuesday', 'Tuesday'),
            ('wednesday', 'Wednesday'),
            ('thursday', 'Thursday'),
            ('friday', 'Friday'),
            ('saturday', 'Saturday'),
            ('sunday', 'Sunday'),
        ], 'Day of week', help=''),
        'day': fields.integer('Day of month'), # FIXME: validate the range of this.
        'invoices': fields.many2many('account.invoice', string='Invoices'),
    }

    def default_get(self, cr, uid, fields, context=None):
        if not context:
            context = {}
        partner_id = context.get('partner_id', False)
        defaults = super(self.__class__, self).default_get(cr, uid, fields, context=context)
        defaults.update({ 'partner_id': partner_id, 'day': 1 })
        return defaults

    def consolidate_invoices(self, cr, uid, ids, context=None):
        mod_obj = self.pool.get('ir.model.data')
        if context is None:
            context = {}
        result = mod_obj._get_id(cr, uid, 'consolidated_invoices', 'consolidated_invoice_tree')
        id = mod_obj.read(cr, uid, result, ['res_id'])
        consolidated_invoice_obj = self.pool.get('account.consolidated.invoice')
        data = self.browse(cr, uid, ids[0], context=context)
        invoice_ids = consolidated_invoice_obj.consolidate_invoices(cr, uid, data, context=context)
        return {
            'name': _('Consolidated Invoice'),
            'view_type': 'form',
            'view_mode': 'tree',
            'view_id': id['res_id'],
            'res_model': 'account.consolidated.invoice',
            'target': 'current',
            'domain': "[('id', 'in', [%s])]" % ','.join([ str(i) for i in invoice_ids]),
            'type': 'ir.actions.act_window',
        }<commit_msg>Bug 3157: Fixed silly infinite loop<commit_after># -*- coding: utf-8 -*-

from openerp.osv import orm, fields
from openerp.tools.translate import _


class consolidator(orm.TransientModel):
    _name = "consolidated.invoice.consolidation"
    _description = "Automatic Invoice Consolidation"


    _columns = {
        'partner_id': fields.many2one('res.partner', 'Partner', change_default=True, readonly=True, required=True),
        'method': fields.selection([
            ('po', 'By Purchase Order Number'),
            ('po_for_selection', 'By Purchase Order Number on selected invoices'),
            ('period', 'By Period'),
            ('po_and_period', 'By Purchase Order Number and Period'),
        ], 'Method', help='Consolidate your invoices by...', required=True), # FIXME: add proper help text.
        'period': fields.selection([
            ('daily', 'Daily'),
            ('weekly', 'Weekly'),
            ('monthly', 'Monthly'),
            ('endofmonth', 'Monthly - End of month'),
        ], 'Period', help=''),
        'dayofweek': fields.selection([
            ('monday', 'Monday'),
            ('tuesday', 'Tuesday'),
            ('wednesday', 'Wednesday'),
            ('thursday', 'Thursday'),
            ('friday', 'Friday'),
            ('saturday', 'Saturday'),
            ('sunday', 'Sunday'),
        ], 'Day of week', help=''),
        'day': fields.integer('Day of month'), # FIXME: validate the range of this.
        'invoices': fields.many2many('account.invoice', string='Invoices'),
    }

    def default_get(self, cr, uid, fields, context=None):
        if not context:
            context = {}
        partner_id = context.get('partner_id', False)
        defaults = super(consolidator, self).default_get(cr, uid, fields, context=context)
        defaults.update({ 'partner_id': partner_id, 'day': 1 })
        return defaults

    def consolidate_invoices(self, cr, uid, ids, context=None):
        mod_obj = self.pool.get('ir.model.data')
        if context is None:
            context = {}
        result = mod_obj._get_id(cr, uid, 'consolidated_invoices', 'consolidated_invoice_tree')
        id = mod_obj.read(cr, uid, result, ['res_id'])
        consolidated_invoice_obj = self.pool.get('account.consolidated.invoice')
        data = self.browse(cr, uid, ids[0], context=context)
        invoice_ids = consolidated_invoice_obj.consolidate_invoices(cr, uid, data, context=context)
        return {
            'name': _('Consolidated Invoice'),
            'view_type': 'form',
            'view_mode': 'tree',
            'view_id': id['res_id'],
            'res_model': 'account.consolidated.invoice',
            'target': 'current',
            'domain': "[('id', 'in', [%s])]" % ','.join([ str(i) for i in invoice_ids]),
            'type': 'ir.actions.act_window',
        }
{'fraction_non_alphanumeric': 0.1588089330024814, 'fraction_numerical': 0.0024813895781637717, 'mean_word_length': 2.573780873970868, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5618209', 'n_tokens_mistral': 1721, 'n_tokens_neox': 1646, 'n_words': 399}