[REF] Banking Mandate: move payment lines list in shortcut button

It allows a user with no access on payment line to open mandates
This commit is contained in:
Thomas Binsfeld
2019-03-12 15:51:56 +01:00
committed by Reyes4711
parent b91ffe730e
commit 1035cb8ff0
3 changed files with 54 additions and 3 deletions

View File

@@ -64,12 +64,44 @@ class AccountBankingMandate(models.Model):
payment_line_ids = fields.One2many(
comodel_name='account.payment.line', inverse_name='mandate_id',
string="Related Payment Lines")
payment_line_ids_count = fields.Integer(
compute='_compute_payment_line_ids_count',
)
_sql_constraints = [(
'mandate_ref_company_uniq',
'unique(unique_mandate_reference, company_id)',
'A Mandate with the same reference already exists for this company!')]
@api.multi
@api.depends('payment_line_ids')
def _compute_payment_line_ids_count(self):
payment_line_model = self.env['account.payment.line']
domain = [('mandate_id', 'in', self.ids)]
res = payment_line_model.read_group(
domain=domain,
fields=['mandate_id'],
groupby=['mandate_id'],
)
payment_line_dict = {}
for dic in res:
mandate_id = dic['mandate_id'][0]
payment_line_dict.setdefault(mandate_id, 0)
payment_line_dict[mandate_id] += dic['mandate_id_count']
for rec in self:
rec.payment_line_ids_count = payment_line_dict.get(rec.id, 0)
@api.multi
def show_payment_lines(self):
self.ensure_one()
return {
'name': _("Payment lines"),
'type': 'ir.actions.act_window',
'view_mode': 'tree,form',
'res_model': 'account.payment.line',
'domain': [('mandate_id', '=', self.id)],
}
@api.multi
@api.constrains('signature_date', 'last_debit_date')
def _check_dates(self):

View File

@@ -31,6 +31,7 @@ class TestInvoiceMandate(TransactionCase):
payment_order.draft2open()
payment_order.open2generated()
payment_order.generated2uploaded()
self.assertEqual(self.mandate.payment_line_ids_count, 1)
def test_post_invoice_02(self):
partner_2 = self._create_res_partner('Jane with ACME Bank')

View File

@@ -23,6 +23,7 @@
<field name="state" widget="statusbar"/>
</header>
<sheet>
<div class="oe_button_box" name="button_box"/>
<div class="oe_title">
<h1>
<field name="unique_mandate_reference"
@@ -44,9 +45,6 @@
<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"/>
@@ -56,6 +54,26 @@
</field>
</record>
<record id="views_mandate_form_buttons" model="ir.ui.view">
<field name="name">view.mandate.form.buttons</field>
<field name="model">account.banking.mandate</field>
<field name="inherit_id" ref="account_banking_mandate.view_mandate_form"/>
<field name="groups_id" eval="[(6, 0, [ref('account_payment_order.group_account_payment')])]"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button name="show_payment_lines"
help="Payment lines"
class="oe_stat_button"
icon="fa-list"
type="object">
<field name="payment_line_ids_count"
widget="statinfo"
string="Payment lines"/>
</button>
</div>
</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>