<commit_before># -*- encoding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2014 Compassion CH (http://www.compassion.ch)
#    Releasing children from poverty in Jesus' name
#    @author: <NAME> <<EMAIL>>
#
#    The licence is in the file __openerp__.py
#
##############################################################################
import logging

from openerp.osv.orm import Model, fields
from openerp.tools import mod10r

logger = logging.getLogger(__name__)


class account_invoice(Model):

    ''' Inherit account.invoice in order to change BVR ref field type '''
    _inherit = "account.invoice"

    _columns = {
        'bvr_reference': fields.char("BVR REF.", size=32,)
    }

    def _check_bvr_ref(self, cr, uid, ids, context=None):
        record = self.browse(cr, uid, ids, context=context)
        for data in record:
            if not data.bvr_reference:
                return True  # No check if no reference
            clean_ref = data.bvr_reference.replace(' ', '')
            if not clean_ref.isdigit() or len(clean_ref) > 27:
                return False
            clean_ref = clean_ref.rjust(27, '0')  # Add zeros to the left
            if not clean_ref == mod10r(clean_ref[0:26]):
                return False

        return True

    _constraints = [(
        _check_bvr_ref,
        'Error: BVR ref should only contain number (max. 27) and spaces.',
        ['bvr_reference'])]


class account_move_line(Model):
    _inherit = 'account.move.line'

    def get_bvr_ref(self, cursor, uid, move_line_id, context=None):
        ''' Overload to take manual bvr ref if exists '''
        if isinstance(move_line_id, (tuple, list)):
            assert len(move_line_id) == 1, "Only 1 ID expected"<commit_msg>Track changes on bvr ref<commit_after># -*- encoding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2014 Compassion CH (http://www.compassion.ch)
#    Releasing children from poverty in Jesus' name
#    @author: <NAME> <<EMAIL>>
#
#    The licence is in the file __openerp__.py
#
##############################################################################
import logging

from openerp.osv.orm import Model, fields
from openerp.tools import mod10r

logger = logging.getLogger(__name__)


class account_invoice(Model):

    ''' Inherit account.invoice in order to change BVR ref field type '''
    _inherit = "account.invoice"

    _columns = {
        'bvr_reference': fields.char("BVR REF.", size=32,
                                     track_visibility='onchange')
    }

    def _check_bvr_ref(self, cr, uid, ids, context=None):
        record = self.browse(cr, uid, ids, context=context)
        for data in record:
            if not data.bvr_reference:
                return True  # No check if no reference
            clean_ref = data.bvr_reference.replace(' ', '')
            if not clean_ref.isdigit() or len(clean_ref) > 27:
                return False
            clean_ref = clean_ref.rjust(27, '0')  # Add zeros to the left
            if not clean_ref == mod10r(clean_ref[0:26]):
                return False

        return True

    _constraints = [(
        _check_bvr_ref,
        'Error: BVR ref should only contain number (max. 27) and spaces.',
        ['bvr_reference'])]


class account_move_line(Model):
    _inherit = 'account.move.line'

    def get_bvr_ref(self, cursor, uid, move_line_id, context=None):
        ''' Overload to take manual bvr ref if exists '''
        if isinstance(move_line_id, (tuple, list)):
            assert len(move_line_id) == 1, "Only 1 ID expected"
{'fraction_non_alphanumeric': 0.18471164309031557, 'fraction_numerical': 0.012513601741022852, 'mean_word_length': 2.802481902792141, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1767536', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1045, 'n_words': 308}