<commit_before>##############################################################################
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published
#    by the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from dateutil.relativedelta import relativedelta
from openerp import models, fields, api, exceptions, _
import calendar


class AccountPaymentTerm(models.Model):
    _inherit = "account.payment.term"

    @api.multi
    def compute(self, value, date_ref=False):
        result = super(AccountPaymentTerm, self).compute(value, date_ref)[0]
        if not result:
            return [result]
        for i, line in enumerate(self.line_ids):
            if not line.payment_days:
                continue
            payment_days = line._decode_payment_days(line.payment_days)
            if not payment_days:
                continue
            payment_days.sort()
            new_date = None
            date = fields.Date.from_string(result[i][0])
            days_in_month = calendar.monthrange(date.year, date.month)[1]
            for day in payment_days:
                if date.day <= day:
                    if day > days_in_month:
                        day = days_in_month
                    new_date = date + relativedelta(day=day)
                    break
            if not new_date:
                day = payment_days[0]
                if day > days_in_month:
                    day = days_in_month
                new_date = date + relativedelta(day=day, months=1)
            result[i] = (fields.Date.to_string(new_date), result[i][1])
        return [result]


class AccountPaymentTermLine(models.Model):
    _inherit = "account.payment.term.line"

    def _decode_payment_days(self, days_char):
        # Admit space, dash and comma as separators
        days_char = days_char.replace(' ', '-').replace(',', '-')
        days_char = [x.strip() for x in days_char.split('-') if x]
        days = [int(x) for x in days_char]
        days.sort()
        return days
<commit_msg>[FIX] account_payment_term_multi_day: Use old API for method compute due to argument incompatibility<commit_after>##############################################################################
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published
#    by the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from dateutil.relativedelta import relativedelta
from openerp import models, fields, api, exceptions, _
import calendar


class AccountPaymentTerm(models.Model):
    _inherit = "account.payment.term"

    def compute(self, cr, uid, id, value, date_ref=False, context=None):
        """This method can't be new API due to arguments names are not
        standard for the API wrapper.
        """
        result = super(AccountPaymentTerm, self).compute(
            cr, uid, id, value=value, date_ref=date_ref, context=context)
        payment_term = self.browse(cr, uid, id, context=context)
        if not result:
            return result
        for i, line in enumerate(payment_term.line_ids):
            if not line.payment_days:
                continue
            payment_days = line._decode_payment_days(line.payment_days)
            if not payment_days:
                continue
            payment_days.sort()
            new_date = None
            date = fields.Date.from_string(result[i][0])
            days_in_month = calendar.monthrange(date.year, date.month)[1]
            for day in payment_days:
                if date.day <= day:
                    if day > days_in_month:
                        day = days_in_month
                    new_date = date + relativedelta(day=day)
                    break
            if not new_date:
                day = payment_days[0]
                if day > days_in_month:
                    day = days_in_month
                new_date = date + relativedelta(day=day, months=1)
            result[i] = (fields.Date.to_string(new_date), result[i][1])
        return result


class AccountPaymentTermLine(models.Model):
    _inherit = "account.payment.term.line"

    def _decode_payment_days(self, days_char):
        # Admit space, dash and comma as separators
        days_char = days_char.replace(' ', '-').replace(',', '-')
        days_char = [x.strip() for x in days_char.split('-') if x]
        days = [int(x) for x in days_char]
        days.sort()
        return days

{'fraction_non_alphanumeric': 0.13289798799858807, 'fraction_numerical': 0.0022943875750088246, 'mean_word_length': 2.4449848024316108, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2559189', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1467, 'n_words': 493}