Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
1265 มุมมอง

Hello, I have a module with this code in stock.picking

# models/stock_picking.py
from odoo import fields, models, api

class StockPicking(models.Model):
_inherit = 'stock.picking'

invoice_status = fields.Boolean(string='Invoice Status', default=False)

@api.depends('sale_id.invoice_ids')
def _compute_invoice_status(self):
for picking in self:
invoices = picking.sale_id.invoice_ids.filtered(lambda inv: inv.state != 'cancel')
picking.invoice_status = bool(invoices)
and this is the xml



stock.picking.form.inherit
stock.picking








If I create a sales order, and confirm it but do not create its corresponding invoice, I want the boolean field to remain False, but if an invoice is created for the sales order, I want it to go to True automatically... .

I tried with that code and some others and it didn't work, can you guide me?

Thanks and sorry for bothering.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello Learning_Odoo,


Hope you are doing well.


I have shared below code please check.


//Code in Comment//


Hope this helps!


Thanks & Regards,

Email:  odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari

อวตาร
ละทิ้ง

Code:

from odoo import fields, models, api, Command

class StockPicking(models.Model):
_inherit = 'stock.picking'

invoice_status = fields.Boolean(string='Invoice Status', store=True)

class SaleOrder(models.Model):
_inherit = 'sale.order'

@api.depends('invoice_ids')
def _compute_invoice_status(self):
for order in self:
if order and order.invoice_ids:
invoices = order.invoice_ids.filtered(lambda inv: inv.state != 'cancel')
order.write({'picking_ids': [
Command.update(picking.id, {
'invoice_status': invoices,
})
for picking in order.picking_ids
if invoices
]})

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ต.ค. 22
4184
3
มี.ค. 18
4705
1
ก.พ. 17
3264
2
ม.ค. 17
7121
1
มี.ค. 15
4002