Skip to Content
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
5 Ответы
5793 Представления

I am trying to add the payment date to the invoice tree but nothing works.

I am using Odoo 14, I have seen the payment date is in model account.payment and the invoice tree view in model account.move, view account.invoice.tree. 

I tried to add  in the model account.move a new field "x_payment_id_date" and then a related field "payment_id.date" but I don't get it to work, I just get an empty field.

By adding in the tree view   I get all the informations from the widget. Is there any option to filter and show only the date? As a work around I can export and in Excel (edit data, divide in columns) delete all but the date.

I got to show the tax number by adding a new field in account.move "x_partner_id_vat" and in related field I add "partner_id.vat". But for the date, I don't get it.

Any help would be appreciated!

Аватар
Отменить
Лучший ответ

How would you display multiple dates in one field in case of multiple payments?

You should create a compute char field and fetch the payment date from the payment widget as follow:

import json

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

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

This way you can fetch the payment date from the widget and add it to your field. This will work even if there will be multiple payments and that is why I have used CHAR field.

Аватар
Отменить

Hi, It works when the invoice is paid or in paid process, but wen there isn't any payment it shows this error:

File "/home/odoo/src/user/ymt_personalizaciones/models/account_move.py", line 18, in _compute_payment_date
for payment_info in json.loads(inv.invoice_payments_widget).get('content', []):
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/odoo/src/odoo/odoo/http.py", line 643, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/odoo/src/odoo/odoo/http.py", line 301, in _handle_exception
raise exception.with_traceback(None) from new_cause
AttributeError: 'bool' object has no attribute 'get'

Автор

I guess the problem Javier found could be solved adding the line "if inv.invoice_payments_widget:" :

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

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

But still I did not get it to work. Which field(s) should I add in "Dependencies"?

Лучший ответ

Hi,

You can try this code

payment_date = fields.Date(string='Payment Date',

                               compute='_compute_payment_date')


@api.depends('line_ids')

def _compute_payment_date(self):

    for rec in self:

        payment_dates = [inv.payment_id.payment_date for inv in rec.line_ids if inv.payment_id]

        rec.payment_date = payment_dates[0] if payment_dates else False

<record id="view_invoice_tree" model="ir.ui.view">
        <field name="name">
http://account.move.view.invoice.tree.inherit.module.name/" target="_blank" style="color: rgb(17, 85, 204);">account.move.view.invoice.tree.inherit.module.name
        </field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_invoice_tree"/>
        <field name="arch" type="xml">
<xpath expr="//field[@name='invoice_date_due']" position="before">
                <field name="payment_date"/>
            </xpath>
         </field>
</record>



Regards


Аватар
Отменить
Лучший ответ

Am working on odoo 15 web studio, I have created a field (date) and include that in my Tree 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) 
 


Аватар
Отменить
Лучший ответ
from odoo import models, fields
import json


class AccountMove(models.Model):
_inherit = 'account.move'
_Inherit = 'account.payment'


def _compute_payment_date(self):
for inv in self:
dates = []
if isinstance(inv.invoice_payments_widget, bool):
inv.payment_date = ''
print('info 1', inv.payment_date)
else:
if inv.payment_state == 'paid' or inv.payment_state == 'partial':

for payment_info in json.loads(inv.invoice_payments_widget).get('content', []):
print('info 2 ', payment_info)
dates.append(payment_info.get('date', ''))
inv.payment_date = ', '.join(dates)
print(inv.payment_date)
else:
inv.payment_date = ''
payment_date = fields.Char(compute='_compute_payment_date')


Аватар
Отменить
Лучший ответ

You can add following in the account.inovice search view




Аватар
Отменить
Автор

Sorry, I do not understand your answer. Throught payment_id I should get the payment date (field date in account.payment) but I just get an empty field.

Related Posts Ответы Просмотры Активность
0
февр. 24
639
0
окт. 23
762
1
мая 23
1840
1
нояб. 22
1306
4
дек. 23
25442