mirror of
https://github.com/bringout/oca-ocb-hr.git
synced 2026-04-25 00:32:01 +02:00
19.0 vanilla
This commit is contained in:
parent
a1137a1456
commit
e1d89e11e3
2789 changed files with 1093187 additions and 605897 deletions
|
|
@ -1,60 +1,51 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models, _
|
||||
from odoo.exceptions import UserError
|
||||
from odoo import api, models, fields, _
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
|
||||
|
||||
class AccountPayment(models.Model):
|
||||
_inherit = "account.payment"
|
||||
|
||||
def action_cancel(self):
|
||||
expense_ids = fields.One2many(related='move_id.expense_ids')
|
||||
|
||||
def _compute_outstanding_account_id(self):
|
||||
# EXTENDS account
|
||||
for payment in self:
|
||||
if payment.expense_sheet_id.payment_mode != 'own_account':
|
||||
continue
|
||||
payment.with_context(skip_account_move_synchronization=True).expense_sheet_id.write({
|
||||
'state': 'approve',
|
||||
'account_move_id': False,
|
||||
})
|
||||
expense_company_payments = self.filtered(lambda payment: payment.expense_ids.payment_mode == 'company_account')
|
||||
for payment in expense_company_payments:
|
||||
payment.outstanding_account_id = payment.expense_ids._get_expense_account_destination()
|
||||
super(AccountPayment, self - expense_company_payments)._compute_outstanding_account_id()
|
||||
|
||||
return super().action_cancel()
|
||||
def _compute_show_require_partner_bank(self):
|
||||
expense_payments = self.filtered(lambda pay: pay.move_id.expense_ids)
|
||||
super()._compute_show_require_partner_bank()
|
||||
expense_payments.require_partner_bank_account = False
|
||||
|
||||
def action_draft(self):
|
||||
employee_expense_sheets = self.reconciled_bill_ids.expense_sheet_id.filtered(
|
||||
lambda expense_sheet: expense_sheet.payment_mode == 'own_account'
|
||||
)
|
||||
employee_expense_sheets.state = 'post'
|
||||
return super().action_draft()
|
||||
def write(self, vals):
|
||||
trigger_fields = {
|
||||
'date', 'amount', 'payment_type', 'partner_type', 'payment_reference',
|
||||
'currency_id', 'partner_id', 'destination_account_id', 'partner_bank_id', 'journal_id'
|
||||
'ref', 'payment_method_line_id'
|
||||
}
|
||||
if self.expense_ids and any(field_name in trigger_fields for field_name in vals):
|
||||
raise UserError(_("You cannot do this modification since the payment is linked to an expense."))
|
||||
return super().write(vals)
|
||||
|
||||
def action_open_expense_report(self):
|
||||
def action_open_expense(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'name': self.expense_sheet_id.name,
|
||||
'name': self.expense_ids.name,
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'views': [(False, 'form')],
|
||||
'res_model': 'hr.expense.sheet',
|
||||
'res_id': self.expense_sheet_id.id
|
||||
'res_model': 'hr.expense',
|
||||
'res_id': self.expense_ids.id,
|
||||
}
|
||||
|
||||
def _synchronize_from_moves(self, changed_fields):
|
||||
# EXTENDS account
|
||||
if self.expense_sheet_id:
|
||||
# Constraints bypass when entry is linked to an expense.
|
||||
# Context is not enough, as we want to be able to delete
|
||||
# and update those entries later on.
|
||||
return
|
||||
return super()._synchronize_from_moves(changed_fields)
|
||||
|
||||
def _synchronize_to_moves(self, changed_fields):
|
||||
# EXTENDS account
|
||||
if self.expense_sheet_id:
|
||||
raise UserError(_("You cannot do this modification since the payment is linked to an expense report."))
|
||||
return super()._synchronize_to_moves(changed_fields)
|
||||
|
||||
def _creation_message(self):
|
||||
# EXTENDS mail
|
||||
self.ensure_one()
|
||||
if self.move_id.expense_sheet_id:
|
||||
return _("Payment created for: %s", self.move_id.expense_sheet_id._get_html_link())
|
||||
if self.move_id.expense_ids:
|
||||
return _("Payment created for: %s", self.move_id.expense_ids._get_html_link())
|
||||
return super()._creation_message()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue