Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Al pagar una factura de cliente o proveedor el tipo de pago no es correcto #46

Open
gbhadolfo opened this issue Mar 23, 2021 · 1 comment

Comments

@gbhadolfo
Copy link

En Odoo 13 CE, para un partner que es cliente y proveedor (tiene facturas y pagos de cliente y de proveedor), al querer pagar una factura de cliente desde la factura, el método default_get en archivo ccount_payment_group/models/account_payment_group.py no setea correctamente el tipo de partner.

Lo solucioné comentando las líneas 696,697,698,699 y agregando la siguiente línea:
rec['partner_type'] = self._context.get('partner_type', self._context.get('default_partner_type', False))
que obtiene el partner_type del contexto pasado directamente del botón Registrar Pago de la factura action_account_invoice_payment_group (archivo account_payment_group/models/account_move.py)
El método action_account_invoice_payment_group en ese último archivo está definido dos veces.

Modifiqué en consecuencia el método action_account_invoice_payment_group para pasar el valor default_partner_type

En localización Adhoc versión 13 el default_get es distinto. https://github.com/ingadhoc/account-payment/blob/13.0/account_payment_group/models/account_move.py
Estimo que funciona.

@gbhadolfo
Copy link
Author


@api.model
def default_get(self, fields):
    # TODO si usamos los move lines esto no haria falta
    rec = super(AccountPaymentGroup, self).default_get(fields)
    to_pay_move_line_ids = self._context.get('to_pay_move_line_ids')
    to_pay_move_lines = self.env['account.move.line'].browse(
        to_pay_move_line_ids).filtered(lambda x: (
            x.account_id.reconcile and
            x.account_id.internal_type in ('receivable', 'payable')))
    if to_pay_move_lines:
        partner = to_pay_move_lines.mapped('partner_id')
        if len(partner) != 1:
            raise ValidationError(_(
                'You can not send to pay lines from different partners'))

        internal_type = to_pay_move_lines.mapped(
            'account_id.internal_type')
        if len(internal_type) != 1:
            raise ValidationError(_(
                'You can not send to pay lines from different partners'))
        rec['partner_id'] = self._context.get('default_partner_id', partner[0].id)
        partner_id = self._context.get('default_partner_id',partner[0].id)
        if partner_id:
            if type(partner_id) == int:
                partner_id = self.env['res.partner'].browse(partner_id)
                
            #if partner_id.supplier_rank:
            #    rec['partner_type'] = 'supplier'
            #if partner_id.customer_rank:
            #    rec['partner_type'] = 'customer'
           
        #rec['partner_type'] = MAP_ACCOUNT_TYPE_PARTNER_TYPE[
        #    internal_type[0]]
        # rec['currency_id'] = invoice['currency_id'][0]
        # rec['payment_type'] = (
        #     internal_type[0] == 'receivable' and
        #     'inbound' or 'outbound')
        rec['partner_type'] = self._context.get('partner_type', self._context.get('default_partner_type', False))
        rec['to_pay_move_line_ids'] = [(6, False, to_pay_move_line_ids)]
    return rec

@api.model
def default_get(self, fields):
    # TODO si usamos los move lines esto no haria falta
    rec = super(AccountPaymentGroup, self).default_get(fields)
    to_pay_move_line_ids = self._context.get('to_pay_move_line_ids')
    to_pay_move_lines = self.env['account.move.line'].browse(
        to_pay_move_line_ids).filtered(lambda x: (
            x.account_id.reconcile and
            x.account_id.internal_type in ('receivable', 'payable')))
    if to_pay_move_lines:
        partner = to_pay_move_lines.mapped('partner_id')
        if len(partner) != 1:
            raise ValidationError(_(
                'You can not send to pay lines from different partners'))

        internal_type = to_pay_move_lines.mapped(
            'account_id.internal_type')
        if len(internal_type) != 1:
            raise ValidationError(_(
                'You can not send to pay lines from different partners'))
        rec['partner_id'] = self._context.get('default_partner_id', partner[0].id)
        partner_id = self._context.get('default_partner_id',partner[0].id)
        if partner_id:
            if type(partner_id) == int:
                partner_id = self.env['res.partner'].browse(partner_id)
                
            #if partner_id.supplier_rank:
            #    rec['partner_type'] = 'supplier'
            #if partner_id.customer_rank:
            #    rec['partner_type'] = 'customer'
           
        #rec['partner_type'] = MAP_ACCOUNT_TYPE_PARTNER_TYPE[
        #    internal_type[0]]
        # rec['currency_id'] = invoice['currency_id'][0]
        # rec['payment_type'] = (
        #     internal_type[0] == 'receivable' and
        #     'inbound' or 'outbound')
        rec['partner_type'] = self._context.get('partner_type', self._context.get('default_partner_type', False))
        rec['to_pay_move_line_ids'] = [(6, False, to_pay_move_line_ids)]
    return rec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant