Skip to Content
Menu
This question has been flagged
1 Reply
2972 Views

Hello, 


By either using a computed field via studio or creating an automated action I am trying to display either a count of payment_tokens or a check box that will identify if any related child records has a credit cards on file? 

I am able to create a related field  that will display the count of payment tokens by contact, but I need to count all the related tokens based on the parent relationship. 

The ultimate goal is to let the sales rep know there is a credit card on file for any of the contacts related to the contact/ parent  that the sales order is created on.

I would appreciate any help on this as it seems possible from the front end developer tools 

Avatar
Discard
Best Answer

Hello Erich, 

You can do this by creating a new calculated field which checks changes on the partner_id.bank_ids. The specific code for counting the banks would be:

for record in self:
  total = len(record.partner_id.bank_ids)
  if record.partner_id.parent_id:
  total += len(record.partner_id.parent_id.bank_ids)
  record["x_bank_count"] = total

Set your dependencies as:

partner_id.bank_ids, partner_id.parent_id.bank_ids	

To create a new field you can go to Settings->Technical->Models search for "sale.order" add a new line on the model. 

If you wanted to change to a boolean, you would just check if the total is > 0. 

Then just inherit the form view and add to the sales order form using:

<?xml version="1.0"?>
<xpath expr="//field[@name='team_id']" position="after">
  <field name="x_bank_count"/>
</xpath>

If you need anything clarifying let me know,

Thanks, 

Avatar
Discard
Related Posts Replies Views Activity
2
Aug 23
1715
1
Dec 17
5590
3
Jul 24
745
2
Apr 24
753
0
Mar 24
229