Skip to Content
Menu
This question has been flagged
3 Replies
2441 Views

Hi,

 

All I need to do is (in Odoo 15 web):

 

When we make payment in Register Payment,

 

We get this Payment date right?

 

I need this payment date as a field, in accounting app > customers > Invoices(List view) with data being populated. 


So that, I would know when the payment is made.

 

If it is possible, kindly guide me with,


Thank You in Advance.
Email: nazeersaleem385@gmail.com


Avatar
Discard
Best Answer

Hello, Naz.
Você pode fazer o seguinte (eu fiz e deu certo):
01) With Studio, create a Date type field in account.move [x_studio_data_de_pagamento_1] (and make it visible only when the entry type is equal to "Vendor Invoice": move_type != "in_invoice");

02) Add it to the tree view;

03) Create an automation with python code in Base Automation so that we can take the value of the 'date' field in account.payment and assign it to this field created with Studio, as follows:

for record in records:

    # Check if the payment state is 'not_paid'

    if record.payment_state == 'not_paid':

        # If the payment state is 'not_paid', clear the field 'x_studio_data_de_pagamento_1'

        record.update({'x_studio_data_de_pagamento_1': False})

    else:

        # Check if the invoice has associated payments

        if record.invoice_payments_widget:

            payments = record.invoice_payments_widget.get('content')

            dates = []

            for payment_info in payments:

                # Extract the payment date

                payment = payment_info.get('date', '')

                if payment:  # Add the date only if it is present

                    # Check if 'payment' is of type datetime.date

                    if isinstance(payment, datetime.date):

                        # Format the date in D/M/Y (Day/Month/Year) for display

                        formatted_date = payment.strftime('%d/%m/%Y')

                        dates.append(formatted_date)  # Use the formatted date

                    else:

                        # Otherwise, assume that 'payment' is a string in the format 'YYYY-MM-DD'

                        formatted_date = payment.split("-")

                        formatted_date = f"{formatted_date[2]}/{formatted_date[1]}/{formatted_date[0]}"

                        dates.append(formatted_date)  # Use the formatted date

            # Update the field 'x_studio_data_de_pagamento_1' with the first payment date

            if dates:  # Check if there are dates to update

                # The first payment date (in 'DD/MM/YYYY' format) will be converted to 'Date' without using fields

                first_payment_date_str = dates[0]  # Example: "26/03/2025"

                try:

                    # Converting the string 'DD/MM/YYYY' to the format 'YYYY-MM-DD'

                    day, month, year = first_payment_date_str.split('/')

                    first_payment_date = f"{year}-{month}-{day}"  # Format 'YYYY-MM-DD'

                    record.update({'x_studio_data_de_pagamento_1': first_payment_date})

                except ValueError:

                    # In case of conversion error, clear the field 'x_studio_data_de_pagamento_1'

                    record.update({'x_studio_data_de_pagamento_1': False})

            else:

                # If there are no dates, clear the field 'x_studio_data_de_pagamento_1'

                record.update({'x_studio_data_de_pagamento_1': False})

In my case, I needed to convert the date presentation to the Brazilian format, but you do not need to include this part of the code in your automation.

Avatar
Discard
Author Best Answer

Hi Mily Shajan,

Thanks for your response. 

am working on odoo 15 web studio, above mentioned code did not work for me but using that code i have modified as per need. The modified code works well for me, i have created a field (date) and include that in my list view and i created one 'automated action' for 'model journal entry', i set trigger for 'on update' and triggers field is 'payment status' and action to do is 'execute python code' this is what i did, I will give that code here :

all_records = env['account.move'].search([])

#model name -> env['account.move']
#to get all the records ->  .search([])

for rec in all_records:    
if rec.payment_state == 'paid':        
​if rec.invoice_payments_widget:
​try:                
​# Parse the JSON string into a dictionary               
​invoice_payments_widget_dict = json.loads(rec.invoice_payments_widget)                                
​# Access the required information                
​content_list = invoice_payments_widget_dict.get('content', [])                                
​if content_list:                    
​content_data = content_list[0]                    
​date_str = content_data.get('date', '')                                        
​if date_str:                        
​rec['x_studio_date_field_a1MrW'] = date_str            
​except Exception:                
​rec['x_studio_date_field_a1MrW'] = None

(Please check the indentation) 
 

Avatar
Discard
Best Answer

Hi Naz

Create a field payment_date in the 'account. move' model  and compute the value 

Try the following code 

class AccountMoveInherit(models.Model):
_inherit = 'account.move'

payment_date = fields.Char(compute='_compute_payment_date')

def _compute_payment_date(self):
self.payment_date = False
for inv in self:
dates = []
if inv.invoice_payments_widget:
payment = inv.invoice_payments_widget.get('content')
for payment_info in payment:
dates.append(str(payment_info.get('date', '')))
inv.payment_date = ', '.join(dates)


Inherit the tree view of the Invoices 'view_out_invoice_tree' and add this field 


Regards


Avatar
Discard
Related Posts Replies Views Activity
4
Jan 24
3261
2
Mar 24
2544
2
Feb 25
1598
2
Apr 24
2380
2
Apr 24
1451