Odoo Decrease Product Quantity Programmatically - odoo

I have created a custom module where there is a field related to product. When the user checkout the product in the custom module, I want to decrease the quantity of product in the override create method. How to achieve this?

Finally, I found the solution code
warehouse = self.env['stock.warehouse'].search(
[('company_id', '=', self.env.company.id)], limit=1
)
self.env['stock.quant'].with_context(inventory_mode=True).create({
'product_id': product_id,
'location_id': warehouse.lot_stock_id.id,
'inventory_quantity': new_quantity,
})

Related

Odoo How Can I update my value from another module's value

I have a question...
As you know in odoo we have sales and purchase apps. I am building a module which will be
provide update product prices in the sales module from the vendor price in the purchase app.
I created a wizard and linked to purchase app.
Okay here is my question...
I want to do this simply.
product.supplierinfo.["price"] = product.product_template["list_price"]
I tried:
for rec self.env["product.supplierinfo"]:
self.env[product.product_template["list_price"]] = rec.["price"]
But as you know it's not working ^^
Any advice for this?
i think you mean to do like this
new_price= self.env[product.product_template].write({
"list_price" : rec.price,
})

PrestaShop add to cart from custom module

I ma working on PrestaShop module, where the user can select some parameters on front view.
I need to add product to cart, including custom price, and selected parameters.
How should I do this? I don't want to override deafult behavior, as not all products will use my component.
Any help would be awesome.
Have a nice day, Bartek.
adding a product to a cart is pretty simple :
First create an empty cart :
$cart=new Cart();
... here you can set your cart properties id_address / id_carrier etc...
$cart->add();
Or, if you already have a cart to use just load the Cart object with its ID and perform :
$cart->updateQty($quantity, $id_product, $id_product_attribute, false);
$cart->update();
You should repeate the updateQty() method for each product / qties you'd need to add to the cart.
In order to customize product prices in cart you have to create product "specific prices" using the SpecificPrice object and bind them to that id_cart :
$mySpecificPrice = new SpecificPrice();
$mySpecificPrice->id_cart = $cart->id;
... add your discount / id_product here on specific price here ...
$mySpecificPrice->add();
Note that you can only set price discounts with SpecificPrice , surcharges are not allowed and will trigger an exeception.
If you need to increase your prices without any core modification, you'll forced to generate an Order and edit the order prices afterward.

Prestashop 1.7 - which hook to use in a module to get the used edited product quantity

I am building a simple module where I need to catch a backoffice quantity modification event (for product or variations) in real time and send the new quantity to an external API.
I am struggling in understanding which hook to use to get the actual user inserted quantity and not the "previous" product quantity.
If I use the static method StockAvailable::getQuantityAvailableByProduct inside the hookActionProductUpdate in my module, I am getting the original product quantity and not the new one, probably because the hook is called before the actual DB update.
Any clue ?
Try with: actionUpdateQuantity
You can pass the next parameters:
array(
'id_product' => (int) Product ID,
'id_product_attribute' => (int) Product attribute ID,
'quantity' => (int) New product quantity
);
List of hook here : https://devdocs.prestashop.com/1.7/modules/concepts/hooks/list-of-hooks/

SAP Hybris - current selected category or product in storefront

is possible get the currently selected product category or product in any mvc controller/service?
Thanks.
Yes, possible.
In ProductPageController.java, you will find ProductData as below.
final ProductData productData = productFacade.getProductForCodeAndOptions(productCode, extraOptions);
You will get Categories from,
productData.getCategories()
and similarly you will get product as well.

How to move field in sale order to stock picking

I have a problem, I made two custom fields in
Sale.order
Stock.picking
How to do when the sale order is confirmed, the field in stock.picking also filled? and the data was picked up from the field at sale.order I've made before.
I'm using odoo 10
Thanks
Yeah, first, depend in your module of sale_stock, then, inherit the sales confirm button and search for the pickings associated:
#api.multi
def action_confirm(self):
result = super(SaleOrder, self).action_confirm()
for order in self:
order.picking_ids.write({'your_field_in_picking': order.your_field_in_sale})
return result
Put it in a class that inherits from sale.order