[FIX] exp_budget_check: in register payment create function active_id doesn't belong account.move
This commit is contained in:
parent
89bc186c91
commit
45bbe558af
|
|
@ -27,6 +27,7 @@
|
||||||
# always loaded
|
# always loaded
|
||||||
'data': [
|
'data': [
|
||||||
'security/security.xml',
|
'security/security.xml',
|
||||||
|
'data/server_action.xml',
|
||||||
'views/account_invoice_view.xml',
|
'views/account_invoice_view.xml',
|
||||||
'views/hr_expense_view.xml',
|
'views/hr_expense_view.xml',
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="server_action_migrate_invoice_rec_id" model="ir.actions.server">
|
||||||
|
<field name="name">Migrate invoice_rec_id to invoice_rec_ids</field>
|
||||||
|
<field name="model_id" ref="base.model_ir_actions_server"/>
|
||||||
|
<field name="state">code</field>
|
||||||
|
<field name="code">
|
||||||
|
env['account.payment'].migrate_invoice_rec_id_to_invoice_rec_ids()
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
|
|
@ -64,17 +64,21 @@ class AccountMove(models.Model):
|
||||||
rec_payment_count = fields.Integer(compute='_compute_rec_payment_count', string='# Payments')
|
rec_payment_count = fields.Integer(compute='_compute_rec_payment_count', string='# Payments')
|
||||||
|
|
||||||
def _compute_rec_payment_count(self):
|
def _compute_rec_payment_count(self):
|
||||||
|
# for invoice in self:
|
||||||
|
# payments = self.env['account.payment'].sudo().search_count([
|
||||||
|
# ('invoice_rec_id', '=', invoice.id)
|
||||||
|
# ])
|
||||||
|
# invoice.rec_payment_count = payments
|
||||||
for invoice in self:
|
for invoice in self:
|
||||||
payments = self.env['account.payment'].sudo().search_count([
|
payments = self.env['account.payment'].sudo().search([]).filtered(lambda r: invoice.id in r.invoice_rec_ids)
|
||||||
('invoice_rec_id', '=', invoice.id)
|
invoice.rec_payment_count = len(payments)
|
||||||
])
|
|
||||||
invoice.rec_payment_count = payments
|
|
||||||
|
|
||||||
def action_open_related_payment_records(self):
|
def action_open_related_payment_records(self):
|
||||||
""" Opens a tree view with related records filtered by a dynamic domain """
|
""" Opens a tree view with related records filtered by a dynamic domain """
|
||||||
payments = self.env['account.payment'].search([
|
# payments = self.env['account.payment'].search([
|
||||||
('invoice_rec_id', '=', self.id)
|
# ('invoice_rec_id', '=', self.id)
|
||||||
]).ids
|
# ]).ids
|
||||||
|
payments = self.env['account.payment'].search([]).filtered(lambda r: self.id in r.invoice_rec_ids).ids
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'name': _('Payments'),
|
'name': _('Payments'),
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
<field name="inherit_id" ref="account.view_account_payment_form"/>
|
<field name="inherit_id" ref="account.view_account_payment_form"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//field[@name='is_matched']" position="after">
|
<xpath expr="//field[@name='is_matched']" position="after">
|
||||||
<field name="invoice_rec_id" invisible="1"/>
|
<field name="invoice_rec_ids" invisible="1"/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from odoo import models, fields, _
|
from odoo import models, fields, api, _
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -6,6 +6,18 @@ class AccountPayment(models.Model):
|
||||||
_inherit = "account.payment"
|
_inherit = "account.payment"
|
||||||
|
|
||||||
invoice_rec_id = fields.Many2one(comodel_name='account.move', string='Invoice', copy=False)
|
invoice_rec_id = fields.Many2one(comodel_name='account.move', string='Invoice', copy=False)
|
||||||
|
invoice_rec_ids = fields.Many2many(comodel_name='account.move', string='Invoice', copy=False)
|
||||||
|
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def migrate_invoice_rec_id_to_invoice_rec_ids(self):
|
||||||
|
"""Migrates Many2one `invoice_rec_id` to Many2many `invoice_rec_ids`."""
|
||||||
|
records = self.search([('invoice_rec_id', '!=', False)])
|
||||||
|
|
||||||
|
for record in records:
|
||||||
|
record.invoice_rec_ids = [(4, record.invoice_rec_id.id)] # Add existing ID
|
||||||
|
|
||||||
|
return f"Migrated {len(records)} records from invoice_rec_id to invoice_rec_ids."
|
||||||
|
|
||||||
|
|
||||||
class AccountPaymentRegister(models.TransientModel):
|
class AccountPaymentRegister(models.TransientModel):
|
||||||
|
|
@ -13,11 +25,12 @@ class AccountPaymentRegister(models.TransientModel):
|
||||||
|
|
||||||
def _create_payments(self):
|
def _create_payments(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
active_id = self.env.context.get('active_id')
|
active_ids = self.env.context.get('active_ids')
|
||||||
if active_id:
|
if active_ids:
|
||||||
invoice_payment = self.env['account.payment'].search(
|
# invoice_payment = self.env['account.payment'].search(
|
||||||
[('invoice_rec_id', '=', active_id),
|
# [('invoice_rec_id', '=', active_id),
|
||||||
('state', '=', 'draft')])
|
# ('state', '=', 'draft')])
|
||||||
|
invoice_payment = self.env['account.payment'].search([('state', '=', 'draft')]).filtered(lambda r: set(active_ids) & set(r.invoice_rec_ids.ids))
|
||||||
if invoice_payment:
|
if invoice_payment:
|
||||||
raise UserError(
|
raise UserError(
|
||||||
_('You can not create payment for this invoice because there is a draft payment for it'))
|
_('You can not create payment for this invoice because there is a draft payment for it'))
|
||||||
|
|
@ -58,7 +71,7 @@ class AccountPaymentRegister(models.TransientModel):
|
||||||
self._reconcile_payments(process_final, edit_mode=edit_mode)
|
self._reconcile_payments(process_final, edit_mode=edit_mode)
|
||||||
for payment in payments:
|
for payment in payments:
|
||||||
if payment.payment_type == 'outbound':
|
if payment.payment_type == 'outbound':
|
||||||
payment.invoice_rec_id = active_id
|
payment.invoice_rec_ids = [(4, active_id) for active_id in active_ids]
|
||||||
payment.action_cancel()
|
payment.action_cancel()
|
||||||
payment.action_draft()
|
payment.action_draft()
|
||||||
return payments
|
return payments
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue