Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
4023 Widoki

I added an onchange function on the field "state" of the sale order to log the state to the log, the function is getting fired when the a quotation is created and it logs the "draft" state of the sale order, but when I confirm it or when create an invoice and pay it, the function is not fired.

The code looks like this:

import logging
from odoo import api, models
_logger = logging.getLogger(__name__)

class SaleOrder(models.Model):
   
_inherit = "sale.order"
    _description = "Sales Order"
    

    @api.onchange('state')
    
def_onchange_sale_order_state(self):
       
_logger.info("on order state change: %s", self.state)


eventually I want to create some records in another model when the quotation is confirmed and turned into sale order.


Any ideas why it's not working?

Awatar
Odrzuć
Najlepsza odpowiedź

While creating and paying invoices sales order invoice state changes not the order state so you must add invoice_status too in your onchange method.

Awatar
Odrzuć
Autor

Well what I'm trying to reach is to have some action fired when the "sale quotation" turned into a "sale order", this is before creating an invoice or paying it.
The flow is "quotation" => "quotation sent" => "sale order", after that you create a invoice.

Najlepsza odpowiedź

Hi Omar,

The Onchange will never get called if the state is changed with the buttons on top of the form. instead the action "action_confirm()" is called. so for your code to work you have to do:

def action_confirm(self):
        _logger.info("on order state change: %s", self.state)
        super().action_confirm()

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
sie 25
2260
Sales quotation Rozwiązane
2
mar 24
3282
2
mar 22
2040
0
kwi 19
5681
1
mar 15
5095