تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
4007 أدوات العرض

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.



الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال
الكاتب

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.

الكاتب أفضل إجابة

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.

الصورة الرمزية
إهمال

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

الكاتب

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

المنشورات ذات الصلة الردود أدوات العرض النشاط
0
يناير 24
1395
2
سبتمبر 15
3901
2
ديسمبر 23
2876
3
أكتوبر 22
6349
1
أكتوبر 22
4269