İçereği Atla
Menü
Bu soru işaretlendi

Hi, I'm attempting to prevent users from canceling a confirmed sale order if there is an invoice confirmed to the client. My current configuration for invoices is "Ordered quantities", not delivered like the majority.

I'm thinking of creating a automated action or something similar that triggers when the user tries to cancel the order.

The logic would be simple, if there is a confirmed invoice, you first need to cancel in order to cancel the sale order.


I don't know where to start or how to do it. Anyone has an idea or has done it before.

I would really appreciate any insights.



Avatar
Vazgeç
En İyi Yanıt

Hi,

You can use the following code in the action.

sale = self.env["sale.order"].search([('name', '=', self.name)]) delivery = self.env["stock.picking"].search([('origin', '=', self.name)])
invoice = self.env["account.move"].search([('invoice_origin', '=', self.name)])
print(invoice.read())
delivery.state = 'draft'
sale.state = "draft"
invoice.state = "draft"
print('delivery', delivery)
print('delivery_o',sale)
for picking in delivery:
for move in picking.move_lines:
move.state = 'draft'
move._do_unreserve()
move.unlink()
picking.unlink()

Hope it helps

Avatar
Vazgeç
Üretici

Hi Cybrosys, thank you for your feedback. I'm encountering the following error:

Down I attached more info on my response.

This is how the code is displayed.
Automated action
Model: Sales Order
Trigger: On creation & Update
Looking forward to hearing from you soon!

Thanks again.

Üretici En İyi Yanıt

Hi Cybrosys, thank you for your feedback. I'm encountering the following error:

This is how the code is displayed.

Automated action

Model: Sales Order

Trigger: On creation & Update

Looking forward to hearing from you soon!

Thanks again.

Avatar
Vazgeç

instead of self.env in the above code, just use env

also please cross and check verify, whether it is a stable solution as the above code uses the name field in the search

Üretici

Hi Niyas, that solved the big problem.
It appears there's a syntax error but I'm not getting why "sale =" is the problem.

SyntaxError : invalid syntax at line 1
sale = env["sale.order"].search([('name', '=', self.name)]) delivery = env["stock.picking"].search([('origin', '=', self.name)])

If I change it t "sale.order ="
Then the following syntax error appears:
Syntax errors detected :

Line 1:
sale.order = env["sale.order"].search([('name', '=', self.name)]) delivery = env["stock.picking"].search([('origin', '=', self.name)])
……………………………………………………………..^ (self.name)])
SyntaxError: invalid syntax

İlgili Gönderiler Cevaplar Görünümler Aktivite
0
Oca 24
1354
2
Eyl 15
3865
2
Ara 23
2783
3
Eki 22
6223
1
Eki 22
4197