<commit_before># -*- coding: utf-8 -*-
# © 2011-2012 Domsense s.r.l. (<http://www.domsense.com>).
# © 2014 Agile Business Group sagl (<http://www.agilebg.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

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


class AccountVoucher(orm.Model):
    _inherit = "account.voucher"

    _columns = {
        'shadow_move_id': fields.many2one(
            'account.move', 'Shadow Entry', readonly=True),
    }

    def is_vat_on_payment(self, voucher):
        vat_on_p = 0
        valid_lines = 0
        if voucher.type in ('payment', 'receipt'):
            for line in voucher.line_ids:
                if line.amount:
                    valid_lines += 1
                    if (line.move_line_id and line.move_line_id.invoice and
                            line.move_line_id.invoice.vat_on_payment):
                        vat_on_p += 1
            if vat_on_p and vat_on_p != valid_lines:
                raise orm.except_orm(
                    _('Error'),
                    _("Can't handle VAT on payment if not every invoice "
                      "is on a VAT on payment treatment"))
        return vat_on_p

    def _compute_allocated_amount(
        self, cr, uid, voucher, allocated=0, write_off=0, context=None
    ):
        # compute the VAT or base line proportionally to
        # the paid amount
        allocated_amount = allocated + write_off
        if (voucher.exclude_write_off and
                voucher.payment_option == 'with_writeoff'):
            # avoid including write-off if set in voucher.
            # That means: use the invoice's total
            # (as we are in 'full reconcile' case)
            allocated_amount = allocated
        return allocated_amount

    def _compute_new_line_amount(
        self, cr, uid, voucher, inv_move_line, amounts_by_invoice, invoice,
        context=None
    ):
        currency_obj = self.pool.get('res.currency')
        allocated_amount = self._compute_allocated_amount(
            cr, uid, voucher,
            allocated=amounts_by_invoice[invoice.id]['allocated'],
            write_off=amounts_by_invoice[invoice.id]['write-off'],
            context=context)
        new_line_amount = currency_obj.round(
            cr, uid, voucher.company_id.currency_id,
            (allocated_amount / amounts_by_invoice[invoice.id]['total']) *
            (inv_move_line.credit or inv_move_line.debit)
        )
        return new_line_amount

    def _compute_new_line_currency_amount(
        self, cr, uid, voucher, inv_move_line, amounts_by_invoice, invoice,
        context=None
    ):
        currency_obj = self.pool.get('res.currency')
        new_line_amount_curr = False
        if (amounts_by_invoice[invoice.id].get('allocated_currency') and
                amounts_by_invoice[invoice.id].get('foreign_currency_id')):
            for_curr = currency_obj.browse(
                cr, uid, amounts_by_invoice[invoice.id]['foreign_currency_id'],
                context=context)
            allocated_amount = self._compute_allocated_amount(
                cr, uid, voucher,<commit_msg>move comment to right place<commit_after># -*- coding: utf-8 -*-
# © 2011-2012 Domsense s.r.l. (<http://www.domsense.com>).
# © 2014 Agile Business Group sagl (<http://www.agilebg.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

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


class AccountVoucher(orm.Model):
    _inherit = "account.voucher"

    _columns = {
        'shadow_move_id': fields.many2one(
            'account.move', 'Shadow Entry', readonly=True),
    }

    def is_vat_on_payment(self, voucher):
        vat_on_p = 0
        valid_lines = 0
        if voucher.type in ('payment', 'receipt'):
            for line in voucher.line_ids:
                if line.amount:
                    valid_lines += 1
                    if (line.move_line_id and line.move_line_id.invoice and
                            line.move_line_id.invoice.vat_on_payment):
                        vat_on_p += 1
            if vat_on_p and vat_on_p != valid_lines:
                raise orm.except_orm(
                    _('Error'),
                    _("Can't handle VAT on payment if not every invoice "
                      "is on a VAT on payment treatment"))
        return vat_on_p

    def _compute_allocated_amount(
        self, cr, uid, voucher, allocated=0, write_off=0, context=None
    ):
        allocated_amount = allocated + write_off
        if (voucher.exclude_write_off and
                voucher.payment_option == 'with_writeoff'):
            # avoid including write-off if set in voucher.
            # That means: use the invoice's total
            # (as we are in 'full reconcile' case)
            allocated_amount = allocated
        return allocated_amount

    def _compute_new_line_amount(
        self, cr, uid, voucher, inv_move_line, amounts_by_invoice, invoice,
        context=None
    ):
        currency_obj = self.pool.get('res.currency')
        allocated_amount = self._compute_allocated_amount(
            cr, uid, voucher,
            allocated=amounts_by_invoice[invoice.id]['allocated'],
            write_off=amounts_by_invoice[invoice.id]['write-off'],
            context=context)
        # compute the VAT or base line proportionally to
        # the paid amount
        new_line_amount = currency_obj.round(
            cr, uid, voucher.company_id.currency_id,
            (allocated_amount / amounts_by_invoice[invoice.id]['total']) *
            (inv_move_line.credit or inv_move_line.debit)
        )
        return new_line_amount

    def _compute_new_line_currency_amount(
        self, cr, uid, voucher, inv_move_line, amounts_by_invoice, invoice,
        context=None
    ):
        currency_obj = self.pool.get('res.currency')
        new_line_amount_curr = False
        if (amounts_by_invoice[invoice.id].get('allocated_currency') and
                amounts_by_invoice[invoice.id].get('foreign_currency_id')):
            for_curr = currency_obj.browse(
                cr, uid, amounts_by_invoice[invoice.id]['foreign_currency_id'],
                context=context)
            allocated_amount = self._compute_allocated_amount(
                cr, uid, voucher,
{'fraction_non_alphanumeric': 0.0946073793755913, 'fraction_numerical': 0.006937874487543362, 'mean_word_length': 2.1447694595934554, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '1355947', 'n_tokens_mistral': 2007, 'n_tokens_neox': 1880, 'n_words': 415}