Skip to content

Commit

Permalink
[IMP] Approbe methods and view
Browse files Browse the repository at this point in the history
  • Loading branch information
maq-adhoc committed May 6, 2024
1 parent e381c90 commit fc64c54
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 98 deletions.
2 changes: 1 addition & 1 deletion account_payment_pro/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Account Payment Super Power",
"version": "17.0.1.1.0",
"version": "17.0.1.2.0",
"category": "Payment",
"website": "www.adhoc.com.ar",
"author": "ADHOC SA",
Expand Down
5 changes: 4 additions & 1 deletion account_payment_pro/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models, api, Command, fields, _

from odoo.exceptions import UserError

class AccountMove(models.Model):
_inherit = "account.move"
Expand Down Expand Up @@ -76,6 +76,9 @@ def button_draft(self):
return super().button_draft()

def _post(self, soft=False):
requiere_double_validation = self.filtered('payment_id.requiere_double_validation')
if requiere_double_validation:
raise UserError(_('The payments %s require approve before post.') % ' '.join(requiere_double_validation.mapped('display_name')))
res = super()._post(soft=soft)
self.pay_now()
return res
16 changes: 8 additions & 8 deletions account_payment_pro/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class AccountPayment(models.Model):
)
writeoff_label = fields.Char(string='Journal Item Label', default='Write-Off',
help='Change label of the counterpart that will hold the payment difference')
is_confirmed = fields.Boolean(tracking=True, copy=False,)
is_approved = fields.Boolean(string="Approved", tracking=True, copy=False,)
requiere_double_validation = fields.Boolean(compute='_compute_requiere_double_validation')

def _check_to_pay_lines_account(self):
Expand All @@ -146,33 +146,33 @@ def _check_to_pay_lines_account(self):
def action_confirm(self):
# chequeamos lineas a pagar antes de confirmar pago para evitar idas y vueltas de validacion
self._check_to_pay_lines_account()
self.filtered(lambda x: x.state == 'draft').is_confirmed = True
self.filtered(lambda x: x.state == 'draft').is_approved = True

def action_unconfirm(self):
# chequeamos lineas a pagar antes de confirmar pago para evitar idas y vueltas de validacion
self._check_to_pay_lines_account()
self.filtered(lambda x: x.state == 'draft').is_confirmed = False
self.filtered(lambda x: x.state == 'draft').is_approved = False

def action_draft(self):
self.is_confirmed = False
self.is_approved = False
super().action_draft()

@api.model
def _get_confimed_blocked_field(self):
return ['partner_id', 'partner_type', 'to_pay_move_line_ids', 'unreconciled_amount',
'withholdable_advanced_amount', 'company_id', 'to_pay_amount', 'amount']
'withholdable_advanced_amount', 'company_id', 'to_pay_amount']

def write(self, vals):
if not self.user_has_groups('account_payment_pro.account_confirm_payment') and self.filtered('is_confirmed'):
if self.filtered('is_approved'):
if set(vals) & set(self._get_confimed_blocked_field()):
raise UserError(_('You cannot modify an approved payment. You must back to edit it.'))
raise UserError(_('Your are trying to modify a protected field on an approved payment. Set it back to edit if you want to make this modification.'))
return super().write(vals)

@api.depends('company_id.double_validation', 'partner_type')
def _compute_requiere_double_validation(self):
double_validation = self.env['account.payment']
if 'force_simple' not in self._context:
double_validation = self.filtered(lambda x: x.company_id.double_validation and not x.is_confirmed and x.partner_type == 'supplier')
double_validation = self.filtered(lambda x: x.company_id.double_validation and not x.is_approved and x.partner_type == 'supplier')
double_validation.requiere_double_validation = True
(self - double_validation).requiere_double_validation = False

Expand Down
201 changes: 113 additions & 88 deletions account_payment_pro/views/account_payment_view.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
<odoo>

<record id="view_account_supplier_payment_tree" model="ir.ui.view">
<field name="name">account.payment.tree</field>
<field name="model">account.payment</field>
<field name="inherit_id" ref="account.view_account_supplier_payment_tree"/>
<field name="arch" type="xml">
<field name="state" position="after">
<field name="is_approved" optional="hide"/>
</field>
</field>
</record>
<record id="view_account_payment_search" model="ir.ui.view">
<field name="name">account.payment.search</field>
<field name="model">account.payment</field>
<field name="inherit_id" ref="account.view_account_payment_search"/>
<field name="arch" type="xml">
<filter name="date" position='after'>
<separator/>
<filter string="Approved" name="is_approved" domain="[('is_approved', '=', True), ('state', '=', 'draft')]"/>
<filter string="Not approved" name="not_is_approved" domain="[('is_approved', '=', False), ('state', '=', 'draft')]"/>
</filter>
</field>
</record>
<record id="view_account_payment_form" model="ir.ui.view">
<field name="name">account.payment.form</field>
<field name="model">account.payment</field>
Expand All @@ -9,14 +31,24 @@
<field name="commercial_partner_id" invisible="True"/>
<field name="is_internal_transfer" invisible="True"/>
<field name="requiere_double_validation" invisible="True"/>
<field name="is_confirmed" invisible="True"/>
<field name="is_approved" invisible="True"/>
</form>
<xpath expr="//div[@name='button_box']" position="after">
<span class="badge rounded-pill text-bg-warning float-end fs-6" invisible="not requiere_double_validation">
<i class="fa fa-fw fa-remove" aria-label="Requiere double validation" title="double_validation" role="img"/>
<span class="d-none d-md-inline">Requiere double validation</span>
</span>
<span class="badge rounded-pill text-bg-success float-end fs-6" invisible="not is_approved">
<i class="fa fa-fw fa-check" aria-label="Approved" title="Approved" role="img"/>
<span class="d-none d-md-inline">Approved</span>
</span>
</xpath>
<button name="action_post" position="attributes">
<attribute name="invisible" add="requiere_double_validation" separator=" or "></attribute>
</button>
<button name="action_post" position="before">
<button name="action_post" position="before">
<button name="action_confirm" class="oe_highlight" string="Approve" groups="account_payment_pro.account_confirm_payment" invisible="state != 'draft' or not requiere_double_validation" type="object"/>
<button name="action_unconfirm" string="Back to Edit" invisible="state == 'draft' and not is_confirmed" type="object"/>
<button name="action_unconfirm" string="Back to Edit" invisible="state == 'draft' and not is_approved" type="object"/>

</button>
<!-- seccion para mejora pagos en otra moneda -->
Expand All @@ -26,98 +58,91 @@
<field name="force_amount_company_currency" invisible="True"/>
<label for="amount_company_currency" string="(on company currency)" invisible="not other_currency"/>
<div name="amount_company_currency" class="o_row" invisible="not other_currency">
x <field name="exchange_rate"/> = <field name="amount_company_currency" readonly="state != 'draft'"/>
</div>
x <field name="exchange_rate"/>
= <field name="amount_company_currency" readonly="state != 'draft'"/>
</div>
<group name="group2" position="after">
<group name="group3" invisible="is_internal_transfer">
<field name="selected_debt" invisible="state not in ('draft')"/>
<field name="matched_amount" invisible="state != 'posted'"/>
<field name="amount_residual" invisible="state != 'posted'"/>
<field name="unreconciled_amount" invisible="state not in ['draft'] or partner_type != 'supplier'" readonly="state not in ['draft']"/>
<field name="to_pay_amount" invisible="state not in ['draft'] or partner_type != 'supplier'" readonly="state not in ['draft']"/>
</group>
<group name="group4" invisible="is_internal_transfer">
<field name="payment_total"/>
<field name="payment_difference" invisible="state not in ('draft')"/>
<div invisible="payment_difference &lt;= 0.0" colspan="2">
<field name="payment_difference_handling" widget="radio" nolabel="1"/>
<div invisible="payment_difference_handling == 'open'">
<label for="writeoff_account_id" string="Post Difference In" class="oe_edit_only"/>
<field name="writeoff_account_id"
string="Post Difference In"
options="{'no_create': True}"
required="payment_difference_handling == 'reconcile'"/>
<label for="writeoff_label" class="oe_edit_only" string="Label"/>
<field name="writeoff_label" required="payment_difference_handling == 'reconcile'"/>
</div>
</div>
<group name="group2" position="after">
<group name="group3" invisible="is_internal_transfer">
<field name="selected_debt" invisible="state not in ('draft')"/>
<field name="matched_amount" invisible="state != 'posted'"/>
<field name="amount_residual" invisible="state != 'posted'"/>
<field name="unreconciled_amount" invisible="state not in ['draft'] or partner_type != 'supplier'" readonly="state not in ['draft']"/>
<field name="to_pay_amount" invisible="state not in ['draft'] or partner_type != 'supplier'" readonly="state not in ['draft']"/>
</group>
<group name="group4" invisible="is_internal_transfer">
<field name="payment_total"/>
<field name="payment_difference" invisible="state not in ('draft')"/>
<div invisible="payment_difference &lt;= 0.0" colspan="2">
<field name="payment_difference_handling" widget="radio" nolabel="1"/>
<div invisible="payment_difference_handling == 'open'">
<label for="writeoff_account_id" string="Post Difference In" class="oe_edit_only"/>
<field name="writeoff_account_id" string="Post Difference In" options="{'no_create': True}" required="payment_difference_handling == 'reconcile'"/>
<label for="writeoff_label" class="oe_edit_only" string="Label"/>
<field name="writeoff_label" required="payment_difference_handling == 'reconcile'"/>
</div>
</group>
</div>
</group>
<sheet>
<notebook invisible="is_internal_transfer">
<page string="Debts" invisible="state != 'draft'">
<p>
</group>
<sheet>
<notebook invisible="is_internal_transfer">
<page string="Debts" invisible="state != 'draft'">
<p>
Payment will be automatically matched with the oldest lines of this list (by maturity date). You can remove any line you dont want to be matched.
</p>
<button name="add_all" string="Add All / Refresh" invisible="state != 'draft'" type="object"/>
<button name="remove_all" string="Remove All" invisible="state != 'draft'" type="object"/>
<button name="%(action_account_payment_invoice_wizard)d" string="+ Debit Note" invisible="state != 'draft'" type="action" context="{'internal_type': 'debit_note'}"/>
<button name="%(action_account_payment_invoice_wizard)d" string="+ Credit Note" invisible="state != 'draft'" context="{'refund': True}" type="action"/>
<field
name="to_pay_move_line_ids"
readonly="state != 'draft'"
context="{'tree_view_ref': 'account_payment_pro.view_move_line_tree'}"
domain="[('partner_id.commercial_partner_id', '=', commercial_partner_id),('account_id.reconcile', '=', True),('reconciled', '=', False), ('full_reconcile_id', '=', False), ('company_id', '=', company_id), ('move_id.state', '=', 'posted'), ('account_id.account_type', '=', 'asset_receivable' if partner_type == 'customer' else 'liability_payable')]"
help="Payment will be automatically matched with the oldest lines of this list (by maturity date). You can remove any line you dont want to be matched."/>
</page>
<page string="Paid" invisible="state != 'posted'">
<field name="matched_move_line_ids" context="{'tree_view_ref': 'account_payment_pro.view_move_line_with_matched_tree'}"/>
</page>
</notebook>
</sheet>
</p>
<button name="add_all" string="Add All / Refresh" invisible="state != 'draft'" type="object"/>
<button name="remove_all" string="Remove All" invisible="state != 'draft'" type="object"/>
<button name="%(action_account_payment_invoice_wizard)d" string="+ Debit Note" invisible="state != 'draft'" type="action" context="{'internal_type': 'debit_note'}"/>
<button name="%(action_account_payment_invoice_wizard)d" string="+ Credit Note" invisible="state != 'draft'" context="{'refund': True}" type="action"/>
<field name="to_pay_move_line_ids" readonly="state != 'draft'" context="{'tree_view_ref': 'account_payment_pro.view_move_line_tree'}" domain="[('partner_id.commercial_partner_id', '=', commercial_partner_id),('account_id.reconcile', '=', True),('reconciled', '=', False), ('full_reconcile_id', '=', False), ('company_id', '=', company_id), ('move_id.state', '=', 'posted'), ('account_id.account_type', '=', 'asset_receivable' if partner_type == 'customer' else 'liability_payable')]" help="Payment will be automatically matched with the oldest lines of this list (by maturity date). You can remove any line you dont want to be matched."/>
</page>
<page string="Paid" invisible="state != 'posted'">
<field name="matched_move_line_ids" context="{'tree_view_ref': 'account_payment_pro.view_move_line_with_matched_tree'}"/>
</page>
</notebook>
</sheet>

</field>
</record>
<record id="view_move_line_tree" model="ir.ui.view">
<field name="name">account.move.line.tree</field>
<field name="model">account.move.line</field>
<field eval="99" name="priority"/>
<field name="arch" type="xml">
<tree string="Journal Items" edit="1">
<field name="date" readonly="True"/>
<field name="date_maturity" optional="hide" readonly="True"/>
<field name="move_id" required="0" readonly="True"/>
<field name="journal_id" options='{"no_open":True}' readonly="True"/>
<field name="name" readonly="True"/>
<field name="ref" optional="hide" readonly="True"/>
<field name="statement_id" column_invisible="True" readonly="True"/>
<field name="account_id" options='{"no_open":True}' domain="[('company_id', '=', company_id)]" readonly="True"/>
<field name="balance" optional="hide" string="Amount" readonly="True"/>
<field name="amount_residual" sum="Total" readonly="True"/>
<field name="amount_currency" groups="base.group_multi_currency" readonly="True"/>
<field name="amount_residual_currency" optional="hide" groups="base.group_multi_currency" readonly="True"/>
<field name="currency_id" column_invisible="True" readonly="True"/>
<field name="company_currency_id" column_invisible="True" readonly="True"/>
<field name="company_id" column_invisible="True" readonly="True"/>
<!--button type="object" icon="fa-external-link" help="Open Related Document" name="action_open_related_document"/-->
</tree>
</field>
</record>
</field>
</record>
<record id="view_move_line_tree" model="ir.ui.view">
<field name="name">account.move.line.tree</field>
<field name="model">account.move.line</field>
<field eval="99" name="priority"/>
<field name="arch" type="xml">
<tree string="Journal Items" edit="1">
<field name="date" readonly="True"/>
<field name="date_maturity" optional="hide" readonly="True"/>
<field name="move_id" required="0" readonly="True"/>
<field name="journal_id" options='{"no_open":True}' readonly="True"/>
<field name="name" readonly="True"/>
<field name="ref" optional="hide" readonly="True"/>
<field name="statement_id" column_invisible="True" readonly="True"/>
<field name="account_id" options='{"no_open":True}' domain="[('company_id', '=', company_id)]" readonly="True"/>
<field name="balance" optional="hide" string="Amount" readonly="True"/>
<field name="amount_residual" sum="Total" readonly="True"/>
<field name="amount_currency" groups="base.group_multi_currency" readonly="True"/>
<field name="amount_residual_currency" optional="hide" groups="base.group_multi_currency" readonly="True"/>
<field name="currency_id" column_invisible="True" readonly="True"/>
<field name="company_currency_id" column_invisible="True" readonly="True"/>
<field name="company_id" column_invisible="True" readonly="True"/>
<!--button type="object" icon="fa-external-link" help="Open Related Document" name="action_open_related_document"/-->
</tree>
</field>
</record>

<record id="view_move_line_with_matched_tree" model="ir.ui.view">
<field name="name">account.move.line.tree</field>
<field name="model">account.move.line</field>
<field eval="99" name="priority"/>
<field name="mode">primary</field>
<field name="inherit_id" ref="account_payment_pro.view_move_line_tree"/>
<field name="arch" type="xml">
<field name="amount_residual" position="replace">
<field name="payment_matched_amount" string="Paid Amount" sum="Total"/>
</field>
<record id="view_move_line_with_matched_tree" model="ir.ui.view">
<field name="name">account.move.line.tree</field>
<field name="model">account.move.line</field>
<field eval="99" name="priority"/>
<field name="mode">primary</field>
<field name="inherit_id" ref="account_payment_pro.view_move_line_tree"/>
<field name="arch" type="xml">
<field name="amount_residual" position="replace">
<field name="payment_matched_amount" string="Paid Amount" sum="Total"/>
</field>
</record>
<!-- <record id="view_account_payment_form2" model="ir.ui.view">
</field>
</record>
<!-- <record id="view_account_payment_form2" model="ir.ui.view">
<field name="name">account.payment.form</field>
<field name="model">account.payment</field>
<field name="inherit_id" ref="account.view_account_payment_form"/>
Expand Down

0 comments on commit fc64c54

Please sign in to comment.