diff --git a/odex25_accounting/odex25_account_payment_fix/models/account_payment.py b/odex25_accounting/odex25_account_payment_fix/models/account_payment.py index f73095259..0e6bbc8f8 100644 --- a/odex25_accounting/odex25_account_payment_fix/models/account_payment.py +++ b/odex25_accounting/odex25_account_payment_fix/models/account_payment.py @@ -48,23 +48,45 @@ class AccountPayment(models.Model): group_name = self.env.ref(group_xml_id).name raise AccessError(_("You do not have the necessary permissions (%s) to perform this action.") % group_name) - def action_post(self): - if self.payment_type == 'outbound': - self._check_permission('odex25_account_payment_fix.group_posted') - res = super(AccountPayment, self).action_post() + # def action_post(self): + # if self.payment_type == 'outbound': + # self._check_permission('odex25_account_payment_fix.group_posted') + # res = super(AccountPayment, self).action_post() - for payment in self: - payment.invalidate_cache() - payment.state = 'posted' - if payment.analytic_account_id and payment.move_id: + # for payment in self: + # payment.invalidate_cache() + # payment.state = 'posted' + # if payment.analytic_account_id and payment.move_id: - for line in payment.move_id.line_ids: - if line.account_id.id == payment.destination_account_id.id: - line.analytic_account_id = payment.analytic_account_id.id - return res + # for line in payment.move_id.line_ids: + # if line.account_id.id == payment.destination_account_id.id: + # line.analytic_account_id = payment.analytic_account_id.id + # return res + def action_post(self): + if self.payment_type == 'outbound': + self._check_permission('odex25_account_payment_fix.group_posted') + + res = super(AccountPayment, self).action_post() + + for payment in self: + payment.state = 'posted' + + if payment.analytic_account_id and payment.move_id: + + target_lines = payment.move_id.line_ids.filtered( + lambda line: line.account_id.id == payment.destination_account_id.id + ) + + + target_lines.write({'analytic_account_id': payment.analytic_account_id.id}) + + target_lines.invalidate_cache() + target_lines.read(['analytic_account_id']) + + return res def action_cancel(self): payment_state = self.state