This question has been flagged
1 Reply
2449 Views

how can i know that the customer invoice is created by validating sales order or manually create by input manually ? i have to filter customer invoice only from sales order , not manually created . is there anyway to know the different ?

thanks

 

EDIT

i use this code but it didn't work ..

my python code :

        'invoice_id': fields.many2one('account.invoice',string='Invoice',required=True, domain=[('origin', '=', True)]),

my xml code:

       <field name="invoice_id" context="{'form_view_ref':'account.invoice_form'}" domain="[('state','=','paid'),('type','=','out_invoice'),('branch_id','=',branch_id),('division','=',division)]" on_change="_onchange_invoice(invoice_id)"/>

 

Avatar
Discard
Best Answer

@Ajeng, customer invoices created from sales order will be linked to the sale order at sale order's invoice_ids field, which is a many2many.  So, what you can do is to create a reverse many2many field at account.invoice, and if you need, create a function field on account.invoice that counts the number of sale.order that this invoice is linked to.

Note that this is not 100% foolproof as people can create modules to link account.invoice to sale.order.  However, if the idea is to separate which account.invoices are related to sale.order and which are not, the above method should suffice.

Avatar
Discard
Author

@ivan thanks for the answer , the field 'invoice_id' above i store it in new object. So it didn't inherit to the other object. But i have to filter order line from account.invoice that has source document from sales order. in order to do that i have to use domain 'origin' but it didn't work.

Origin does not guarantee and is only available in account.invoice. If you want to access the sale.order.line, then you can do it from the following relationship: sale.order --> sale.order.line (through order_id of sale.order.line --> account.invoice.line (through invoice_lines of sale.order.line, you can create the reverse many2many field in account.invoice.line to ease the searching) --> account.invoice (through invoice_id of account.invoice.line). From that relationship you can create proxy fields (related fields) that will help you to do the search. Also, I'm not quite sure why you want to filter order line (I presume you mean sale.order.line) from account.invoice? Maybe if you described what is the ultimate objective (instead of just asking how to do it in certain way), you can get a better help.

Author

i am following your answer, but how can i get invoice that have a 'paid' state ?

Put a domain to limit the returned records.