In the window Aged Balance, I want to add a new field that make me see only the unpaid invoices i mean i want to see the invoices contrubted on the calculation of the balance related to specifi party , i have add a new field
contributing_invoices = fields.One2Many(
'account.invoice', 'party',
'Contributing Invoices',
domain=[('state', 'in', ['open'])]
)
def get_contributing_invoices(self, name):
"""
Returns invoices that have an outstanding balance.
"""
pool = Pool()
Invoice = pool.get('account.invoice')
domain = [
('party', '=', self.party.id),
('company', '=', self.company.id),
('state', 'in', ['open']) # Only unpaid invoices
]
invoices = Invoice.search(domain)
invoices_with_balance = [
invoice for invoice in invoices if invoice.amount_to_pay > 0
]
return [invoice.id for invoice in invoices_with_balance]
—> the problem that show me (2) i mean number between parenthsese and when i click i cant find the invoices contributed
I think you have a problem with your field definition:
The field its defined as One2Many but you should declare it as Function field and include the function name to be called so Tryton is able to compute the field using the code you created latter.
# field for invoices contributing to the balance
contributing_invoices = fields.Function(fields.One2Many(
'account.invoice', 'party',
'Contributing Invoices',
domain=[('state', 'in', ['open'])]
), 'get_contributing_invoices')
def get_contributing_invoices(self, name):
"""
Returns invoices that have an outstanding balance.
"""
pool = Pool()
Invoice = pool.get('account.invoice')
domain = [
('party', '=', self.party.id),
('company', '=', self.company.id),
('state', 'in', ['open']) # Only unpaid invoices
]
invoices = Invoice.search(domain)
invoices_with_balance = [
invoice for invoice in invoices if invoice.amount_to_pay > 0
]
return [invoice.id for invoice in invoices_with_balance]
—> also i have putcalled this field the xml list view of the Aged balance
but i still when i click the list view i can not see the invoices related to this party that are not paid , must i ad another additional thing in the XML view ?
In list view the client can only display the number of record for any xxx2Many field.
If you want to see the content you must add the field to a form view.
But in your case, I think a relate is more appropriate than a Function with an instance getter (which will be very slow if there are many parties).
Also you may consider to display the paybale/receivable lines instead of the invoices which provide more accurate information than the invoice in case of partial payment etc. Such relate may be included in standard.