Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
4126 Näkymät

The scenario is we have 2 or more lines with the same product, same cost, same quantity so the total price also same.

now what we have, i create another invoice with the  previous quantity and previous amount. which means the previous invoice values is it's previous amount and quantity. Now my problem is if i create the invoice with the same product and cost and etc... as same. i can't get each line seperately because i can't differentiate the line with this scenario.

Note: With the different product my expectation working fine. but, same product it's not. 

My Code is:

@api.one
@api.depends
('invoice_id.former_invoice_id')
def _get_previous_qty(self):
if self.invoice_id.former_invoice_id:
lines = self.invoice_id.former_invoice_id.invoice_line_ids.filtered(lambda r: r.product_id.id == self.product_id.id and r.price_unit == self.price_unit)
        self.prev_qty = sum(lines.mapped('total_qty')) 

Any suggestions for me?

Avatar
Hylkää
Paras vastaus

Hi,

Put if condition when you get two lines then you get last created line by its id in desc order.

or

Use sorted function 

 lines = self.invoice_id.former_invoice_id.invoice_line_ids.sorted()

and then if get len ids > 1 then select last id.

or

 You can put index or sequence in lines and use it to differentiate record.

https://www.odoo.com/apps/modules/10.0/order_line_serial_number/

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
marrask. 19
6050
2
toukok. 25
1192
1
huhtik. 25
3575
0
maalisk. 24
1328
2
tammik. 24
2761