<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 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 api, models, fields
from odoo.addons.sponsorship_compassion.models.product import \
    GIFT_CATEGORY


class AccountInvoice(models.Model):
    """ Add mailing origin in invoice objects. """
    _inherit = 'account.invoice'

    @api.model
    def create_from_wordpress(
            self, partner_id, wp_origin, amount, fund, child_code,
            pf_payid, payment_mode_name, utm_source, utm_medium, utm_campaign
    ):
        """
         Utility for invoice donation creation.
        :param partner_id: odoo partner_id
        :param wp_origin: the fund code in wordpress
        :param amount: amount of donation
        :param fund: the fund code in wordpress
        :param child_code: child local_id
        :param pf_payid: postfinance transaction number
        :param payment_mode_name: the payment_mode identifier from postfinance
        :param utm_source: the utm identifier in wordpress
        :param utm_medium: the utm identifier in wordpress
        :param utm_campaign: the utm identifier in wordpress
        :return: invoice_id
        """
        product = self.env['product.product']
        if fund:
            product = product.search([
                ('default_code', 'ilike', fund)])
        sponsorship = self.env['recurring.contract']
        if child_code:
            sponsorship = sponsorship.search([
                '|', ('partner_id', '=', partner_id),
                ('correspondent_id', '=', partner_id),
                ('child_code', '=', child_code)
            ], order='id desc', limit=1)
        payment_mode = self.env['account.payment.mode'].search([
            ('name', '=', payment_mode_name),
            ('active', '=', True)
        ])
        if not payment_mode:
            # Credit Card Journal
            journal = self.env['account.journal'].search([
                ('code', '=', 'CCRED')
            ], limit=1)
            payment_mode.create({
                'name': payment_mode_name,
                'payment_method_id': 1,  # Manual inbound
                'payment_type': 'inbound',
                'bank_account_link': 'fixed',
                'fixed_journal_id': journal.id,
                'active': True
            })
        origin = 'WP ' + wp_origin + ' ' + str(pf_payid)
        invoice = self.search([
            ('user_id', '=', self.env.uid),
            ('partner_id', '=', partner_id),
            ('state', '=', 'draft')
        ])
        if not invoice:
            account = self.env['account.account'].search([
                ('code', '=', '1050')])
            internet_id = self.env.ref('utm.utm_medium_website').id
            utms = self.env['utm.mixin'].get_utms(
                utm_source, utm_medium, utm_campaign)
            # Compute invoice date for birthday gifts
            invoice_date = fields.Date.today()
            invoice = self.create({
                'partner_id': partner_id,
                'payment_mode_id': payment_mode.id,
                'origin': origin,
                'reference': str(pf_payid),<commit_msg>CO-2144 FIX bug when updating existing invoice from wordpress<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 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 api, models, fields
from odoo.addons.sponsorship_compassion.models.product import \
    GIFT_CATEGORY


class AccountInvoice(models.Model):
    """ Add mailing origin in invoice objects. """
    _inherit = 'account.invoice'

    @api.model
    def create_from_wordpress(
            self, partner_id, wp_origin, amount, fund, child_code,
            pf_payid, payment_mode_name, utm_source, utm_medium, utm_campaign
    ):
        """
         Utility for invoice donation creation.
        :param partner_id: odoo partner_id
        :param wp_origin: the fund code in wordpress
        :param amount: amount of donation
        :param fund: the fund code in wordpress
        :param child_code: child local_id
        :param pf_payid: postfinance transaction number
        :param payment_mode_name: the payment_mode identifier from postfinance
        :param utm_source: the utm identifier in wordpress
        :param utm_medium: the utm identifier in wordpress
        :param utm_campaign: the utm identifier in wordpress
        :return: invoice_id
        """
        product = self.env['product.product']
        if fund:
            product = product.search([
                ('default_code', 'ilike', fund)])
        sponsorship = self.env['recurring.contract']
        if child_code:
            sponsorship = sponsorship.search([
                '|', ('partner_id', '=', partner_id),
                ('correspondent_id', '=', partner_id),
                ('child_code', '=', child_code)
            ], order='id desc', limit=1)
        payment_mode = self.env['account.payment.mode'].search([
            ('name', '=', payment_mode_name),
            ('active', '=', True)
        ])
        if not payment_mode:
            # Credit Card Journal
            journal = self.env['account.journal'].search([
                ('code', '=', 'CCRED')
            ], limit=1)
            payment_mode.create({
                'name': payment_mode_name,
                'payment_method_id': 1,  # Manual inbound
                'payment_type': 'inbound',
                'bank_account_link': 'fixed',
                'fixed_journal_id': journal.id,
                'active': True
            })
        origin = 'WP ' + wp_origin + ' ' + str(pf_payid)
        invoice = self.search([
            ('user_id', '=', self.env.uid),
            ('partner_id', '=', partner_id),
            ('state', '=', 'draft')
        ])
        utms = self.env['utm.mixin'].get_utms(
            utm_source, utm_medium, utm_campaign)
        if not invoice:
            account = self.env['account.account'].search([
                ('code', '=', '1050')])
            internet_id = self.env.ref('utm.utm_medium_website').id
            # Compute invoice date for birthday gifts
            invoice_date = fields.Date.today()
            invoice = self.create({
                'partner_id': partner_id,
                'payment_mode_id': payment_mode.id,
                'origin': origin,
                'reference': str(pf_payid),
{'fraction_non_alphanumeric': 0.15875071963154866, 'fraction_numerical': 0.004029936672423719, 'mean_word_length': 2.1586363636363637, 'pattern_counts': {'":': 0, '<': 9, '<?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': '4930536', 'n_tokens_mistral': 2011, 'n_tokens_neox': 1904, 'n_words': 461}