Browse Source

[UPDT] Updated to query 'export_stockinfo_xls'

pull/145/head
Ajmal JK 5 years ago
parent
commit
b4f0daa624
  1. 2
      export_stockinfo_xls/__manifest__.py
  2. 6
      export_stockinfo_xls/doc/RELEASE_NOTES.md
  3. 68
      export_stockinfo_xls/models/wizard.py

2
export_stockinfo_xls/__manifest__.py

@ -22,7 +22,7 @@
{ {
'name': 'Export Product Stock in Excel', 'name': 'Export Product Stock in Excel',
'version': '13.0.1.1.0', 'version': '13.0.1.1.1',
'summary': "Current Stock Report for all Products in each Warehouse", 'summary': "Current Stock Report for all Products in each Warehouse",
'description': "Current Stock Report for all Products in each Warehouse, Odoo 13,Odoo13", 'description': "Current Stock Report for all Products in each Warehouse, Odoo 13,Odoo13",
'category': 'Warehouse', 'category': 'Warehouse',

6
export_stockinfo_xls/doc/RELEASE_NOTES.md

@ -11,6 +11,12 @@ Initial Commit Export Product Stock in Excel
#### FIX #### FIX
Updation Of Export Product Stock in Excel Updation Of Export Product Stock in Excel
#### 05.02.2020
#### Version 13.0.1.1.1
#### UPDT
Changed to query

68
export_stockinfo_xls/models/wizard.py

@ -70,38 +70,52 @@ class StockReport(models.TransientModel):
lines = [] lines = []
categ_id = data.mapped('id') categ_id = data.mapped('id')
if categ_id: if categ_id:
stock_history = self.env['product.product'].search([('categ_id', 'in', categ_id)]) categ_products = self.env['product.product'].search([('categ_id', 'in', categ_id)])
else: else:
stock_history = self.env['product.product'].search([]) categ_products = self.env['product.product'].search([])
for obj in stock_history: product_ids = tuple([pro_id.id for pro_id in categ_products])
sale_query = """
SELECT sum(s_o_l.product_uom_qty) AS product_uom_qty, s_o_l.product_id FROM sale_order_line AS s_o_l
JOIN sale_order AS s_o ON s_o_l.order_id = s_o.id
WHERE s_o.state IN ('sale','done')
AND s_o.warehouse_id = %s
AND s_o_l.product_id in %s group by s_o_l.product_id"""
purchase_query = """
SELECT sum(p_o_l.product_qty) AS product_qty, p_o_l.product_id FROM purchase_order_line AS p_o_l
JOIN purchase_order AS p_o ON p_o_l.order_id = p_o.id
INNER JOIN stock_picking_type AS s_p_t ON p_o.picking_type_id = s_p_t.id
WHERE p_o.state IN ('purchase','done')
AND s_p_t.warehouse_id = %s AND p_o_l.product_id in %s group by p_o_l.product_id"""
params = warehouse, product_ids if product_ids else (0, 0)
self._cr.execute(sale_query, params)
sol_query_obj = self._cr.dictfetchall()
self._cr.execute(purchase_query, params)
pol_query_obj = self._cr.dictfetchall()
for obj in categ_products:
sale_value = 0 sale_value = 0
purchase_value = 0 purchase_value = 0
product = self.env['product.product'].browse(obj.id) for sol_product in sol_query_obj:
sale_obj = self.env['sale.order.line'].search([('order_id.state', 'in', ('sale', 'done')), if sol_product['product_id'] == obj.id:
('product_id', '=', product.id), sale_value = sol_product['product_uom_qty']
('order_id.warehouse_id', '=', warehouse)]) for pol_product in pol_query_obj:
for i in sale_obj: if pol_product['product_id'] == obj.id:
sale_value = sale_value + i.product_uom_qty purchase_value = pol_product['product_qty']
purchase_obj = self.env['purchase.order.line'].search([('order_id.state', 'in', ('purchase', 'done')), virtual_available = obj.with_context({'warehouse': warehouse}).virtual_available
('product_id', '=', product.id), outgoing_qty = obj.with_context({'warehouse': warehouse}).outgoing_qty
('order_id.picking_type_id', '=', warehouse)]) incoming_qty = obj.with_context({'warehouse': warehouse}).incoming_qty
for i in purchase_obj: available_qty = virtual_available + outgoing_qty - incoming_qty
purchase_value = purchase_value + i.product_qty value = available_qty * obj.standard_price
test = product.with_context(warehouse=warehouse)._compute_quantities()
available_qty = product.virtual_available + \
product.outgoing_qty - \
product.incoming_qty
value = available_qty * product.standard_price
vals = { vals = {
'sku': product.default_code, 'sku': obj.default_code,
'name': product.name, 'name': obj.name,
'category': product.categ_id.name, 'category': obj.categ_id.name,
'cost_price': product.standard_price, 'cost_price': obj.standard_price,
'available': available_qty, 'available': available_qty,
'virtual': product.with_context({'warehouse': warehouse}).virtual_available, 'virtual': virtual_available,
'incoming': product.with_context({'warehouse': warehouse}).incoming_qty, 'incoming': incoming_qty,
'outgoing': product.with_context({'warehouse': warehouse}).outgoing_qty, 'outgoing': outgoing_qty,
'net_on_hand': product.with_context({'warehouse': warehouse}).qty_available, 'net_on_hand': obj.with_context({'warehouse': warehouse}).qty_available,
'total_value': value, 'total_value': value,
'sale_value': sale_value, 'sale_value': sale_value,
'purchase_value': purchase_value, 'purchase_value': purchase_value,

Loading…
Cancel
Save