Can not see contributed invoices on the calculation of the balance

Hi ,

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

any help will be appreciated, Thanks.

Hi,

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.

Hope this helps!

Hi, Thank you Mr.pokoli, i did that,

    # 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.

Hi Mr.ced , I tried to add the view form that contain just the field

       <record model="ir.ui.view" id="aged_balance_view_form">
            <field name="model">account.aged_balance</field>
            <field name="type">form</field>
            <field name="name">aged_balance_form</field>
        </record>
        <record model="ir.action.act_window" id="act_aged_balance_form">
            <field name="name">Invoices</field>
            <field name="res_model">account.invoice</field>
            <field name="context_model">account.invoice</field>
        </record>
        <record model="ir.action.act_window.view" id="act_aged_balance_form_view2">
            <field name="sequence" eval="10"/>
            <field name="view" ref="aged_balance_view_form"/>
            <field name="act_window" ref="act_aged_balance_form"/>
      </record>

and I have created the aged_balance_form.xml

<?xml version="1.0"?>
<form>
    <field name="contributing_invoices"/>
</form>

but when i click the menu Aged Balance doesnt work like before it seems i dont click it

You must add your new view to the existing ir.action.act_window define in the account module (not to a new one).

In the account module, The only existant ir.action.act_window related to account.aged_balance is

        <record model="ir.action.act_window" id="act_aged_balance_list">
            <field name="name">Aged Balance</field>
            <field name="res_model">account.aged_balance</field>
            <field name="context_model">account.aged_balance.context</field>
        </record>

How i can add here my new view form

I have tried to add

    <record model="ir.action.act_window.view" id="act_aged_balance_form_view2">
        <field name="sequence" eval="10"/>
        <field name="view" ref="aged_balance_view_form"/>
        <field name="act_window" ref="act_aged_balance_list"/>
    </record>

–>but it doesnt work still doesnt show me any invoice

Here’s an example of extending a view:

And many examples in the tryton code: