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

Hi, I'm trying to sync our products quantities with our e-commerce platform.


I created a custom module and inherited product.product module and I'm overriding the write method as shown below


 def write(self, values):
record = super(product_product, self).write(values)

for record in self:

product_id = record.id
qty = record.qty_available


data ={
"model": "product.product",
"date": str(current_time),
"product_id" : str(product_id),
"available_qty": str(qty)
}
            
            requests.post('https://somelink/sendDataToEcommerce',json=data)


The write method is being triggered but the quantity is still remaining the same when retrieving it . I also tried it on the stock.move module but its also not changing. however in odoo its appearing fine.


How can I retrieve the on hand quantity after it has been modified manually

Awatar
Odrzuć
Najlepsza odpowiedź

Hi Ahmad,

may be this is due to write method, because write method not return object.

You can create new function and return data from that function

def get_product_stock(self, product_id):

    product = self.env['product.product'].browse(product_id)    

    # current_time = SET CURRENT TIME HERE    

    data ={

            "model": "product.product",

            "date": str(current_time),

            "product_id" : str(product_id),

            "available_qty": str(product.qty_available)

            }

    return requests.post('https://somelink/sendDataToEcommerce',json=data)

--

Regards
Haresh Kansara
Odoo Application Engineer

https://join.skype.com/invite/dl0S6rgZ7GBF  
Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
16
sty 21
17081
3
maj 23
14454
2
wrz 20
2784
3
sie 24
1983
1
sty 22
3083