Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
4413 Lượt xem

Hi guys,

I've extended the ability to automatically generate invoices from contracts. In the contracts page I've added the ability to add cars to contracts and on this car you can set a tax. See an example image here.

The cars field is a many2one to fleet.vehicle and inside this many2one I have a many2many relation to account.tax.
Python code:

_columns = {
   'car_id': fields.many2one('fleet.vehicle', 'Cars'), 
   'car_line_tax_id': fields.many2many('account.tax', 'account_car_line_tax', 'car_line_id', 'tax_id', string='BTW')

I now add a car to the car_id many2one and fill in a tax (for example: VAT-OUT-21-SERVICES). I then run the automatic planner which triggers a Python method that generates concept invoices from the contracts:

def _prepare_invoice_lines(self, cr, uid, contract, fiscal_position_id, context=None):
    //Lots of irrelevant code.
    //Loop over all cars that are added to the car_id list.
    for line in contract.recurring_invoice_car_line_ids: 
        //Add every car to the invoices_lines
        invoice_lines.append((0, 0, { 
            //Fill up the fields
            'quantity': line.car_number_of_units or 0.0,
            'price_unit': line.car_rent_price or 0.0, 
            //This line isn't working well. I know the filled in tax is in car_line_tax_id but it doesn't get filled in on the invoice.
'invoice_line_tax_id': line.car_line_tax_id,

So everything works fine except 'invoice_line_tax_id': line.car_line_tax_id. For some reason the tax doesn't get filled in in account.invoice.form on the field invoice_lines_tax_id. You can see an example here from both screens.

Why is this? Did I do something wrong or?

Thanks,
Yenthe



Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Try adding in such a way:

'invoice_line_tax_id': [(6, 0, [x.id for x in line.car_line_tax_id)], 
Ảnh đại diện
Huỷ bỏ
Tác giả

Works perfect! So why do you have to loop over them? Why can't I simply call the id? Because it can contain multiple values? Accepted & upvoted, thanks Zbik!

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 2 21
4912
0
thg 8 17
3683
1
thg 8 16
4327
1
thg 3 16
5889
1
thg 3 15
17982