Calculate available inventory in OpenERP - odoo

I am developing a custom module for OpenERP 7 that will track hardware installed in various venues. I have the total stock levels recorded in the Warehouse module, but I want to be able to calculate and display amount of each product that is available and the amount that is currently deployed. I'm having trouble figuring out how to do this. I have been looking at this rent module and they seem to do something with stock picking and workflows, but I'm new to OpenERP and not really sure how that works.
The other way I was thinking of was to loop through the deployments and simply calculate the amount of each item, and use functional fields to display it, but I'm not sure if that would even work, or how to do it without hard-coding all the various items.

Have a look at product.py in the stock module, specifically the get_product_available method. This allows you to pack various filter parameters into the context and then it calculates and returns stock as the net of inbound and outbound stock moves.
This method also gets used in the functional fields qty_available, virtual_available, incoming_qty and outgoing_qty. There is reasonably good explanations in the help comments in the module.

In OpenERP, something is in your stock when there's a stock move (object stock.move) with that product to your physical location as destination location, defined on Warehouse object for "Inventory Location" field. Let's say you have recorded 2 moves:
Move 1
Source Location: Supplier
Destination Location: Stock
Qty: 2
Move 2
Source Location: Stock
Destination Location: Deployed Products
Qty: 1
If you open your products list you'll see that you have 1qty of your product available. OpenERP sums all the moves for that product to and from your Stock location. So if you have no other specific needs, recording moves to some sort "Deployed Products" location should be enough.

Related

Adding new product with category tree - specific price problems

I installed an add-on for bulk action (called ba_importer v 1.1.24), I upload an Excel file with my data and create a group of products.
I can set the categories' tree or manually add ID of main categories and associated. I tried with no luck to use the tree features (like Home/Products/etc) and so I use all the ID of main category and all the associated. The result is a product with the correct categories set, but with no specific price from the customer group linked to a category.
I tried to edit a single product, remove all categories and set it one by one (set one, save, set one, save etc.) and then the specific price from the group linked to a category appears to the product.
Is there a better solution? I'm thinking about make a personal PHP page that reads an Excel file and sets all the information about the product, but I'm scared to face the same problem with the specific price. 
There is no such thing as "category-related specific price",
if you have specific prices tied to customer groups , these are created as a result of the add/update product action with ps_specific_price DB entries having id_group with your restricted ID.
It is likely that the bulk module acts directly with DB queries to speed up things and bypasses this operation, I've seen this behaviour with those kind of modules in the past.
Since you are talking of a paid add-on, I would definitely seek help from the developer.

How to mass update the stock quantity of a batch of products in PrestaShop 1.7.6?

I work in the integration of an ERP (Random) and PrestaShop, one of the points considered by the integration is the stock level of the products. When there are movements in the stock of the products in the ERP originating outside of PrestaShop (for example, transfers between warehouses, purchases, external sales, etc.), these stock variations must be synchronized with the physical stock (physical_stock) of PrestaShop, because the reserved stock (stock_reserved) exists only in the PrestaShop context and is related to the reserved products in orders that have not yet been dispatched, while the available stock (stock_available) does not consider the reserved stock by design, then if the Stock that comes from the ERP is assigned to the available stock, the stock reserved until now would double. On the other hand, the physical stock considers both the available stock and the reserved stock, then the stock that comes from the ERP is assigned to the physical stock, the reserved stock is maintained and the available stock will vary depending on the following relation:
stock_available.quantity = stock_available.physical_quantity - stock_available.reserved_quantity
This is currently working correctly in production, however, what I am looking for is to design these operations in the best way through a PrestaShop module, which through a FrontController receives an ajax request where one of the request parameters (Request->_ POST['stock_quantity_changes']) is an input in array format, for example:
[
$id_stock_avaiblable_1 => $new_quantity_1,
$id_stock_avaiblable_2 => $new_quantity_2,
...
]
with which I would like to update the set of stocks that it contains in a single operation. So far, I found method src/PrestaShopBundle/Entity/Repository/StockRepository.php->bulkUpdateStock (https://github.com/PrestaShop/PrestaShop/blob/100c5c028b05c579f5788a036041e45cef510e1d/src/PrestaShopBundle/Entity/Repository/StockRepository.php#L102), that would allow me to do what I need, however I have not figured out how to create a proper instance of this class (StockRepository) yet. The StockRepository-> bulkUpdateStock method receives a set of stock movements (MovementsCollection) and with it, updates a set of available stocks, both in individual products and in pack's if necessary, in addition, records the stock movements (StockMvt's), executes the actionUpdateQuantity hook for each modified stock and removes the value of each modified stock from the cache, all this can be checked in /src/Core/Stock/StockManager.php->updateQuantity (https://github.com/PrestaShop/PrestaShop/blob/100c5c028b05c579f5788a036041e45cef510e1d/src/Core/Stock/StockManager.php#L153). Finally the method bulkUpdateStock synchronize the level of physical stock with the available stock + reserved stock. I am interested in using all this logic when updating a set of stock to adapt it to PrestaShop's operation, since currently only updating the values ​​of the stock_available table I am not registering the StockMvt's, cleaning the cache or executing the actionUpdateQuantity hook.
In summary, I found the StockRepository class that contains the bulkUpdateStock method that would allow me to correctly update the levels of a set of stocks in a single operation, however, to instantiate this class requires a set of parameters, which can be verified in https://github.com/PrestaShop/PrestaShop/blob/100c5c028b05c579f5788a036041e45cef510e1d/src/PrestaShopBundle/Entity/Repository/StockRepository.php#L72, and so far I have not found any instantiation examples for this class in the source code, I have only found code that uses this class already instantiated, as you can check in src/PrestaShopBundle/Controller/Api/StockController.php (https://github.com/PrestaShop/PrestaShop/blob/100c5c028b05c579f5788a036041e45cef510e1d/src/PrestaShopBundle/Controller/Api/StockController.php#L126). So the question finally is, how can I properly instantiate the StockRepository class ?, or is there any alternative to do what I need ?, regards :)

Can we increase shipping rates in shopify using shopify script?

I found similar question in the forum, and from this answer I come to know about Career service. Which looks promising initially, but after reading the doc from here, I found that there is an issue for my use case.
This is my use case:
There will be multiple items in the cart with different delivery dates set(I store delivery dates in the line_item property)
now when user go to checkout the shipping rate has to be calculated based on the delivery dates(which are stored in the line item property for each line item)
shipping price should be calculated like ...... if there is only one delivery day, we need to offer x price, if there are two different delivery dates we need to offer 2x price and so on....
so the issue is, Carrier Service uses Server side cashing and it will only ask for price if any of these(variant IDs, default shipping box weight and dimensions, variant quantities, carrier service ID, origin address, destination address, item weights and signatures) field change. It doesn't include line item properties(where I have stored delivery dates).
I have also checked the shopify scripts from here, but after some mockups I come to know that we can only provide discount to the existing shipping rates and can not add new shipping method, or increase shipping price for existing shipping method.
Please help me to find a solution for this problem.

Only show in stock products OpenERP

When I open the location structure of the warehouse and check the current inventory of a particular location, it shows me all products (even when stock is 0).
Is there a way to hide the products that are not in stock in that particular location (or remove them from being able to show in that location)?
To achieve this functionality, you have to customize addons side code of stock and product,
You have to implement funt_search method in qty_available function of product, to search product based on codition.
And in the wizard you have to pass domain, of qty_avalable > 0 at wizard,.
For refrence you can see in openerp latest trunk stock module code.
Hope this help

Prestashop: use BlockLayered class methods and/or DB tables for price range button?

I've got to build a standalone menu button with submenu that contains links to price ranges.
I activated the blocklayered module (not for this task, only for regular left-column filters). So the relative db tables are in place and populated.
I want to make a controller specific for price ranges. So I've got to do the right query and maybe set up the same url vars as the blocklayered module so they wil not conflict.
Would it be too crazy to import blocklayered or blocklayered-ajax in my controller and use part of their functionality? Maybe not good because of object duplication or other issues?
Or maybe, would it be a bad idea to use the blocklayered tables (for example layered_price_index) to help me get filtered products? I'm wandering if it would be a better solution than re-doing all by myself, or if instead it's not good for some reason.
Any idea?
It really depends on which amount (among the ones below) you would like to take into account in your price range filter:
Amount without taxes
Amount including taxes
Amount including discount/promotion
Amount in several currencies or only one currency
Amount for a specific customer group or for everyone
Amount base on any other product price rule
The easy way:
You can build a price range controller easily by yourself, handling only a single currency and prices without taxes and reduction. It will probably be 90% accurate (because of the missing discounts a product might not show up for a certain range).
In that case, you can easily build a query on the ps_product and ps_specific_price tables and SELECT in real-time the right products for a given range.
The proper way:
You want to handle discounts, price rules, specific prices, etc. If you build a real-time query including all these calculations and parameters, it may slow down the server.
Build a product price cache or re-use the one setup by the Block Layered module.