mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD] Payment Wizard on invoice with folio payments from other partner
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
'category': 'Generic Modules/Hotel Management',
|
||||
'website': 'https://github.com/hootel/hootel',
|
||||
'depends': [
|
||||
'base',
|
||||
'sale_stock',
|
||||
'account_payment_return',
|
||||
'partner_firstname',
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
# Copyright 2017 Dario Lodeiros
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||
from odoo import models, fields, api, _
|
||||
import json
|
||||
from odoo.tools import float_is_zero, float_compare, pycompat
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
@@ -36,6 +38,8 @@ class AccountInvoice(models.Model):
|
||||
from_folio = fields.Boolean(compute='_computed_folio_origin')
|
||||
folio_ids = fields.Many2many(
|
||||
comodel_name='hotel.folio', compute='_computed_folio_origin')
|
||||
outstanding_folios_debits_widget = fields.Text(compute='_get_outstanding_folios_JSON')
|
||||
has_folios_outstanding = fields.Boolean(compute='_get_outstanding_folios_JSON')
|
||||
|
||||
@api.multi
|
||||
def action_invoice_open(self):
|
||||
@@ -55,3 +59,51 @@ class AccountInvoice(models.Model):
|
||||
if folios:
|
||||
inv.from_folio = True
|
||||
inv.folio_ids = [(6, 0, folios.ids)]
|
||||
|
||||
@api.one
|
||||
def _get_outstanding_folios_JSON(self):
|
||||
self.outstanding_folios_debits_widget = json.dumps(False)
|
||||
if self.from_folio:
|
||||
payment_ids = self.folio_ids.mapped('payment_ids.id')
|
||||
if self.state == 'open':
|
||||
domain = [('account_id', '=', self.account_id.id),
|
||||
('partner_id', '!=', self.env['res.partner']._find_accounting_partner(self.partner_id).id),
|
||||
('reconciled', '=', False),
|
||||
('payment_id', 'in', payment_ids),
|
||||
'|',
|
||||
'&', ('amount_residual_currency', '!=', 0.0), ('currency_id','!=', None),
|
||||
'&', ('amount_residual_currency', '=', 0.0), '&', ('currency_id','=', None), ('amount_residual', '!=', 0.0)]
|
||||
if self.type in ('out_invoice', 'in_refund'):
|
||||
domain.extend([('credit', '>', 0), ('debit', '=', 0)])
|
||||
type_payment = _('Outstanding credits in Folio')
|
||||
else:
|
||||
domain.extend([('credit', '=', 0), ('debit', '>', 0)])
|
||||
type_payment = _('Outstanding debits')
|
||||
info = {'title': '', 'outstanding': True, 'content': [], 'invoice_id': self.id}
|
||||
lines = self.env['account.move.line'].search(domain)
|
||||
currency_id = self.currency_id
|
||||
if len(lines) != 0:
|
||||
for line in lines:
|
||||
# get the outstanding residual value in invoice currency
|
||||
if line.currency_id and line.currency_id == self.currency_id:
|
||||
amount_to_show = abs(line.amount_residual_currency)
|
||||
else:
|
||||
amount_to_show = line.company_id.currency_id.with_context(date=line.date).compute(abs(line.amount_residual), self.currency_id)
|
||||
if float_is_zero(amount_to_show, precision_rounding=self.currency_id.rounding):
|
||||
continue
|
||||
if line.ref :
|
||||
title = '%s : %s' % (line.move_id.name, line.ref)
|
||||
else:
|
||||
title = line.move_id.name
|
||||
info['content'].append({
|
||||
'journal_name': line.ref or line.move_id.name,
|
||||
'title': title,
|
||||
'amount': amount_to_show,
|
||||
'currency': currency_id.symbol,
|
||||
'id': line.id,
|
||||
'position': currency_id.position,
|
||||
'digits': [69, self.currency_id.decimal_places],
|
||||
})
|
||||
info['title'] = type_payment
|
||||
self.outstanding_folios_debits_widget = json.dumps(info)
|
||||
self.has_folio_outstanding = True
|
||||
|
||||
@@ -28,7 +28,7 @@ class ResPartner(models.Model):
|
||||
compute='_compute_reservations_count')
|
||||
folios_count = fields.Integer('Folios', compute='_compute_folios_count')
|
||||
unconfirmed = fields.Boolean('Unconfirmed', default=True)
|
||||
main_partner_id = fields.Many2one('res.partner')
|
||||
main_partner_id = fields.Many2one('res.partner', string='Destination Partner fusion')
|
||||
|
||||
@api.model
|
||||
def name_search(self, name, args=None, operator='ilike', limit=100):
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
<xpath expr="//button[@name='%(account.action_account_invoice_payment)d']" position="attributes">
|
||||
<attribute name="attrs">{'invisible': ['|',('from_folio','=',True)]}</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='outstanding_credits_debits_widget']" position="after">
|
||||
<field name="outstanding_folios_debits_widget" colspan="2" nolabel="1" widget="payment" attrs="{'invisible': [('state', 'not in', 'open')]}"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user