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

Hey! By default, Odoo can automatically create assets from invoice lines. However, it does not pay attention to quantity on the invoice lines. In other words, all the quantity of the same invoice line will be merge into ONE asset. I want odoo to create an asset for each quantity in the invoice line how can we do that. Right now asset create method for odoo is


@api.one
def asset_create(self):
if self.asset_category_id:
vals = {
'name': self.name,
'code': self.invoice_id.number or False,
'category_id': self.asset_category_id.id,
'value': self.price_subtotal_signed,
'partner_id': self.invoice_id.partner_id.id,
'company_id': self.invoice_id.company_id.id,
'currency_id': self.invoice_id.company_currency_id.id,
'date': self.invoice_id.date_invoice,
'invoice_id': self.invoice_id.id,
}
changed_vals = self.env['account.asset.asset'].onchange_category_id_values(vals['category_id'])
vals.update(changed_vals['value'])
asset = self.env['account.asset.asset'].create(vals)
if self.asset_category_id.open_asset:
asset.validate()
return True
Kindly share if you have any suggestion.
Ảnh đại diện
Huỷ bỏ
Tác giả

Anyone????

Câu trả lời hay nhất

Hi,

You have to loop on line qunatity field and modify the value field to have the unit.price but in company currency and since there no filed for signed unit price
you will divided the self.price_subtotal_signed field by line qunatity to get unit price signed.

So you will ovveride asset_create as below and you donot need to call the super:


@api.one
def asset_create(self):
for x in range(self.quantity):
if self.asset_category_id:
vals = {
'name': self.name,
'code': self.invoice_id.number or False,
'category_id': self.asset_category_id.id,
'value': self.price_subtotal_signed / self.quantity,
'partner_id': self.invoice_id.partner_id.id,
'company_id': self.invoice_id.company_id.id,
'currency_id': self.invoice_id.company_currency_id.id,
'date': self.invoice_id.date_invoice,
'invoice_id': self.invoice_id.id,
}
changed_vals = self.env['account.asset.asset'].onchange_category_id_values(vals['category_id'])
vals.update(changed_vals['value'])
asset = self.env['account.asset.asset'].create(vals)
if self.asset_category_id.open_asset:
asset.validate()
return True
Ảnh đại diện
Huỷ bỏ
Tác giả

hey! Thanks for replying.

I have tried your code but it is giving me this error

TypeError: 'float' object cannot be interpreted as an integer

How to fix that sir? Thanks

Tác giả

Hey man i have fixed this using

for x in numpy.arange(self.quantity):

and it is working now. Thanks for your answer

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 1 20
5555
2
thg 5 19
8646
3
thg 7 22
7534
0
thg 11 21
2891
0
thg 8 20
3784