Skip to content

Commit

Permalink
[FIX+IMP] account_banking_mandate: Several things
Browse files Browse the repository at this point in the history
* Bug OCA#96 bad use of new API
* [Usability] mandates: search by reference, add group_by, add seq type in tree view
* Add scheme in mandate tree+search view
* Replace tabs by spaces in mandate views
* account_banking_mandate/views/account_banking_mandate_view.xml: convert from dos to unix format
* Add multi-company rule on account.banking.mandate
  • Loading branch information
Alexis de Lattre authored and misern2 committed Feb 23, 2020
1 parent 6f84c60 commit fec70e6
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 112 deletions.
1 change: 1 addition & 0 deletions account_banking_mandate/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'views/account_payment_view.xml',
'views/res_partner_bank_view.xml',
'data/mandate_reference_sequence.xml',
'security/mandate_security.xml',
'security/ir.model.access.csv',
],
'demo': [],
Expand Down
14 changes: 7 additions & 7 deletions account_banking_mandate/models/payment_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PaymentLine(models.Model):
comodel_name='account.banking.mandate', string='Direct Debit Mandate',
domain=[('state', '=', 'valid')])

@api.multi
@api.model
def create(self, vals=None):
"""If the customer invoice has a mandate, take it
otherwise, take the first valid mandate of the bank account
Expand All @@ -40,12 +40,12 @@ def create(self, vals=None):
vals = {}
partner_bank_id = vals.get('bank_id')
move_line_id = vals.get('move_line_id')
if (self.env.context.get('search_payment_order_type') == 'debit'
and 'mandate_id' not in vals):
if (self.env.context.get('search_payment_order_type') == 'debit' and
'mandate_id' not in vals):
if move_line_id:
line = self.env['account.move.line'].browse(move_line_id)
if (line.invoice and line.invoice.type == 'out_invoice'
and line.invoice.mandate_id):
if (line.invoice and line.invoice.type == 'out_invoice' and
line.invoice.mandate_id):
vals.update({
'mandate_id': line.invoice.mandate_id.id,
'bank_id': line.invoice.mandate_id.partner_bank_id.id,
Expand All @@ -61,8 +61,8 @@ def create(self, vals=None):
@api.one
@api.constrains('mandate_id', 'bank_id')
def _check_mandate_bank_link(self):
if (self.mandate_id and self.bank_id
and self.mandate_id.partner_bank_id.id !=
if (self.mandate_id and self.bank_id and
self.mandate_id.partner_bank_id.id !=
self.bank_id.id):
raise exceptions.Warning(
_("The payment line with reference '%s' has the bank account "
Expand Down
19 changes: 19 additions & 0 deletions account_banking_mandate/security/mandate_security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 Akretion (http://www.akretion.com/)
@author: Alexis de Lattre <[email protected]>
The licence is in the file __openerp__.py
-->


<openerp>
<data noupdate="1">

<record id="account_banking_mandate_rule" model="ir.rule">
<field name="name">Banking Mandate multi-company</field>
<field name="model_id" ref="model_account_banking_mandate"/>
<field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])]</field>
</record>

</data>
</openerp>
217 changes: 112 additions & 105 deletions account_banking_mandate/views/account_banking_mandate_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,117 +6,124 @@
-->
<openerp>
<data>
<record id="view_mandate_form" model="ir.ui.view">
<field name="name">view.mandate.form</field>
<field name="model">account.banking.mandate</field>
<field name="arch" type="xml">
<form string="Banking Mandate" version="7.0">
<header>
<button name="validate" type="object" string="Validate" states="draft" class="oe_highlight"/>
<button name="cancel" type="object" string="Cancel" states="draft,valid"/>
<button name="back2draft" type="object" string="Back to Draft"
states="cancel" groups="account.group_account_manager"
confirm="You should set a mandate back to draft only if you cancelled it by mistake. Do you want to continue?"/>
<field name="state" widget="statusbar"/>
</header>
<sheet>
<div class="oe_title">
<h1>
<field name="unique_mandate_reference"
class="oe_inline"
readonly="1"/>
</h1>
</div>
<group name="main">
<field name="company_id" groups="base.group_multi_company"/>
<field name="partner_bank_id"
invisible="context.get('mandate_bank_partner_view')" />
<field name="partner_id" invisible="context.get('mandate_bank_partner_view')" readonly="True"/>
<field name="signature_date"/>
<field name="scan"/>
<field name="last_debit_date"/>
</group>
<group name="payment_lines" string="Related Payment Lines">
<field name="payment_line_ids" nolabel="1"/>
</group>
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread"/>
</div>
</form>
</field>
</record>

<record id="view_mandate_tree" model="ir.ui.view">
<field name="name">view.mandate.tree</field>
<field name="model">account.banking.mandate</field>
<field name="arch" type="xml">
<tree string="Banking Mandate" colors="blue:state=='draft';black:state in ('expired', 'cancel')">
<field name="company_id" groups="base.group_multi_company"/>
<field name="partner_id" invisible="context.get('mandate_bank_partner_view')"/>
<field name="unique_mandate_reference" string="Reference"/>
<field name="signature_date" string="Signature Date"/>
<field name="last_debit_date"/>
<field name="state"/>
</tree>
</field>
</record>

<record id="view_mandate_search" model="ir.ui.view">
<field name="name">view.mandate.search</field>
<field name="model">account.banking.mandate</field>
<field name="arch" type="xml">
<search string="Search Banking Mandates">
<field name="partner_id"/>
<filter name="draft" string="Draft" domain="[('state', '=', 'draft')]" />
<filter name="valid" string="Valid" domain="[('state', '=', 'valid')]" />
<filter name="cancel" string="Cancelled" domain="[('state', '=', 'cancel')]" />
<filter name="expired" string="Expired" domain="[('state', '=', 'expired')]" />
</search>
</field>
</record>
<record id="view_mandate_form" model="ir.ui.view">
<field name="name">view.mandate.form</field>
<field name="model">account.banking.mandate</field>
<field name="arch" type="xml">
<form string="Banking Mandate" version="7.0">
<header>
<button name="validate" type="object" string="Validate" states="draft" class="oe_highlight"/>
<button name="cancel" type="object" string="Cancel" states="draft,valid"/>
<button name="back2draft" type="object" string="Back to Draft"
states="cancel" groups="account.group_account_manager"
confirm="You should set a mandate back to draft only if you cancelled it by mistake. Do you want to continue?"/>
<field name="state" widget="statusbar"/>
</header>
<sheet>
<div class="oe_title">
<h1>
<field name="unique_mandate_reference"
class="oe_inline"
readonly="1"/>
</h1>
</div>
<group name="main">
<field name="company_id" groups="base.group_multi_company"/>
<field name="partner_bank_id"
invisible="context.get('mandate_bank_partner_view')" />
<field name="partner_id" invisible="context.get('mandate_bank_partner_view')" readonly="True"/>
<field name="signature_date"/>
<field name="scan"/>
<field name="last_debit_date"/>
</group>
<group name="payment_lines" string="Related Payment Lines">
<field name="payment_line_ids" nolabel="1"/>
</group>
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread"/>
</div>
</form>
</field>
</record>

<record id="mandate_action" model="ir.actions.act_window">
<field name="name">Banking Mandates</field>
<field name="res_model">account.banking.mandate</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create a new Banking Mandate.
</p><p>
A Banking Mandate is a document signed by your customer that gives you the autorization to do one or several operations on his bank account.
</p>
</field>
</record>
<record id="view_mandate_tree" model="ir.ui.view">
<field name="name">view.mandate.tree</field>
<field name="model">account.banking.mandate</field>
<field name="arch" type="xml">
<tree string="Banking Mandate" colors="blue:state=='draft';black:state in ('expired', 'cancel')">
<field name="company_id" groups="base.group_multi_company"/>
<field name="partner_id" invisible="context.get('mandate_bank_partner_view')"/>
<field name="unique_mandate_reference" string="Reference"/>
<field name="signature_date" string="Signature Date"/>
<field name="last_debit_date"/>
<field name="state"/>
</tree>
</field>
</record>

<menuitem id="mandate_menu"
parent="account_payment.menu_main_payment"
action="mandate_action"
sequence="20"
/>
<record id="view_mandate_search" model="ir.ui.view">
<field name="name">view.mandate.search</field>
<field name="model">account.banking.mandate</field>
<field name="arch" type="xml">
<search string="Search Banking Mandates">
<field name="unique_mandate_reference" string="Reference or Partner" filter_domain="['|', ('unique_mandate_reference', 'ilike', self), ('partner_id', 'ilike', self)]"/>
<field name="partner_id"/>
<filter name="draft" string="Draft" domain="[('state', '=', 'draft')]" />
<filter name="valid" string="Valid" domain="[('state', '=', 'valid')]" />
<filter name="cancel" string="Cancelled" domain="[('state', '=', 'cancel')]" />
<filter name="expired" string="Expired" domain="[('state', '=', 'expired')]" />
<group string="Group By" name="groupby">
<filter name="signature_date_groupby" string="Signature Date" context="{'group_by': 'signature_date'}"/>
</group>
</search>
</field>
</record>

<!-- notifications in the chatter -->
<record id="mandate_valid" model="mail.message.subtype">
<field name="name">Mandate Validated</field>
<field name="res_model">account.banking.mandate</field>
<field name="default" eval="False"/>
<field name="description">Banking Mandate Validated</field>
</record>
<record id="mandate_action" model="ir.actions.act_window">
<field name="name">Banking Mandates</field>
<field name="res_model">account.banking.mandate</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create a new Banking Mandate.
</p><p>
A Banking Mandate is a document signed by your customer that gives you the autorization to do one or several operations on his bank account.
</p>
</field>
</record>

<menuitem id="mandate_menu"
parent="account_payment.menu_main_payment"
action="mandate_action"
sequence="20"
/>

<!-- notifications in the chatter -->
<record id="mandate_valid" model="mail.message.subtype">
<field name="name">Mandate Validated</field>
<field name="res_model">account.banking.mandate</field>
<field name="default" eval="False"/>
<field name="description">Banking Mandate Validated</field>
</record>

<record id="mandate_expired" model="mail.message.subtype">
<field name="name">Mandate Expired</field>
<field name="res_model">account.banking.mandate</field>
<field name="default" eval="False"/>
<field name="description">Banking Mandate has Expired</field>
</record>

<record id="mandate_cancel" model="mail.message.subtype">
<field name="name">Mandate Cancelled</field>
<field name="res_model">account.banking.mandate</field>
<field name="default" eval="False"/>
<field name="description">Banking Mandate Cancelled</field>
</record>

<record id="mandate_expired" model="mail.message.subtype">
<field name="name">Mandate Expired</field>
<field name="res_model">account.banking.mandate</field>
<field name="default" eval="False"/>
<field name="description">Banking Mandate has Expired</field>
</record>

<record id="mandate_cancel" model="mail.message.subtype">
<field name="name">Mandate Cancelled</field>
<field name="res_model">account.banking.mandate</field>
<field name="default" eval="False"/>
<field name="description">Banking Mandate Cancelled</field>
</record>
</data>
</openerp>

0 comments on commit fec70e6

Please sign in to comment.