Merge pull request #2306 from expsa/samir-aladawi-seperate-hr-expense-customization

Samir aladawi seperate hr expense customization
This commit is contained in:
SamirLADOUI-sa 2025-02-04 12:08:36 +01:00 committed by GitHub
commit 72cfe97cc1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 11 deletions

View File

@ -21,11 +21,11 @@ class AccountMove(models.Model):
# Update attachment count for all records (if necessary)
for record in self:
related_ids = record.ids
related_models = 'account.move'
related_models = ['account.move']
if record.res_id and record.res_model:
related_ids = record.ids + [record.res_id]
related_models = ['account.move', record.res_model]
related_models.append(record.res_model)
action['domain'] = [
('res_model', 'in', related_models),
('res_id', 'in', related_ids),
@ -55,11 +55,11 @@ class AccountMove(models.Model):
('res_id', 'in', self.ids),
]
related_ids = self.ids
related_models = 'account.move'
related_models = ['account.move']
if self.res_id and self.res_model:
related_ids = self.ids + [self.res_id]
related_models = ['account.move', self.res_model]
related_models.append(self.res_model)
action['domain'] = [
('res_model', 'in', related_models),
('res_id', 'in', related_ids),

View File

@ -70,7 +70,7 @@ class AccountMove(models.Model):
# ])
# invoice.rec_payment_count = payments
for invoice in self:
payments = self.env['account.payment'].sudo().search([]).filtered(lambda r: invoice.id in r.invoice_rec_ids)
payments = self.env['account.payment'].sudo().search([]).filtered(lambda r: invoice.id in r.invoice_rec_ids.ids)
invoice.rec_payment_count = len(payments)
def action_open_related_payment_records(self):
@ -78,7 +78,7 @@ class AccountMove(models.Model):
# payments = self.env['account.payment'].search([
# ('invoice_rec_id', '=', self.id)
# ]).ids
payments = self.env['account.payment'].search([]).filtered(lambda r: self.id in r.invoice_rec_ids).ids
payments = self.env['account.payment'].search([]).filtered(lambda r: self.id in r.invoice_rec_ids.ids).ids
return {
'name': _('Payments'),

View File

@ -5,19 +5,27 @@ from odoo.exceptions import UserError
class AccountPayment(models.Model):
_inherit = "account.payment"
# TODO remove this field 'invoice_rec_id' after launching server action server_action_migrate_invoice_rec_id
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)
invoice_rec_ids = fields.Many2many(comodel_name='account.move', copy=False)
@api.model
def migrate_invoice_rec_id_to_invoice_rec_ids(self):
"""Migrates Many2one `invoice_rec_id` to Many2many `invoice_rec_ids`."""
# Get all records where invoice_rec_id is set
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."
if record.invoice_rec_id:
move_id = record.invoice_rec_id.id
if isinstance(move_id, int):
record.write({
'invoice_rec_id': False,
'invoice_rec_ids': [(4, move_id)]
})
print(f">>> Migration completed for {len(records)} records <<<")
class AccountPaymentRegister(models.TransientModel):