mirror of
https://bitbucket.org/presik/trytonpsk-stock_co.git
synced 2023-12-14 05:43:05 +01:00
minor fix
This commit is contained in:
parent
e84364488f
commit
6febd30f81
74
stock.py
74
stock.py
|
@ -291,8 +291,12 @@ class WarehouseStockStart(ModelView):
|
|||
to_date = fields.Date('To Date', required=True)
|
||||
only_minimal_level = fields.Boolean('Only Minimal Level')
|
||||
group_by_location = fields.Boolean('Group By Location')
|
||||
group_by_supplier = fields.Boolean('Group By Supplier')
|
||||
category = fields.Many2One('product.category', 'Category')
|
||||
supplier = fields.Many2One('party.party', 'Supplier')
|
||||
suppliers = fields.Many2Many('party.party', None, None, "Suppliers",
|
||||
domain=[
|
||||
('active', '=', True)
|
||||
])
|
||||
zero_quantity = fields.Boolean('Zero Quantity')
|
||||
|
||||
@staticmethod
|
||||
|
@ -317,21 +321,19 @@ class WarehouseStock(Wizard):
|
|||
|
||||
def do_print_(self, action):
|
||||
category_id = None
|
||||
supplier_id = None
|
||||
if self.start.category:
|
||||
category_id = self.start.category.id
|
||||
if self.start.supplier:
|
||||
supplier_id = self.start.supplier.id
|
||||
data = {
|
||||
'company': self.start.company.id,
|
||||
'locations': [l.id for l in self.start.locations],
|
||||
'location_names': ', '.join([l.name for l in self.start.locations]),
|
||||
'only_minimal_level': self.start.only_minimal_level,
|
||||
'group_by_location': self.start.group_by_location,
|
||||
'group_by_supplier': self.start.group_by_supplier,
|
||||
'zero_quantity': self.start.zero_quantity,
|
||||
'to_date': self.start.to_date,
|
||||
'category': category_id,
|
||||
'supplier': supplier_id,
|
||||
'suppliers': [l.id for l in self.start.suppliers],
|
||||
}
|
||||
return action, data
|
||||
|
||||
|
@ -348,7 +350,7 @@ class WarehouseReport(Report):
|
|||
Product = pool.get('product.product')
|
||||
OrderPoint = pool.get('stock.order_point')
|
||||
Location = pool.get('stock.location')
|
||||
ProductsSupplier = pool.get('purchase.product_supplier')
|
||||
# ProductsSupplier = pool.get('purchase.product_supplier')
|
||||
ids_location = data['locations']
|
||||
locations = Location.browse(data['locations'])
|
||||
dom_products = [
|
||||
|
@ -384,15 +386,8 @@ class WarehouseReport(Report):
|
|||
|
||||
products_ids = min_quantities.keys()
|
||||
dom_products.append(('id', 'in', products_ids))
|
||||
|
||||
supplier = None
|
||||
if data['supplier']:
|
||||
products_supplier = ProductsSupplier.search([
|
||||
('party', '=', data['supplier']),
|
||||
])
|
||||
supplier = products_supplier[0].party.name
|
||||
products_ids = [ps.product.id for ps in products_supplier]
|
||||
dom_products.append(('template', 'in', products_ids))
|
||||
if data['suppliers']:
|
||||
dom_products.append([('template.product_suppliers', 'in', data['suppliers'])])
|
||||
|
||||
total_amount = 0
|
||||
values = {}
|
||||
|
@ -402,27 +397,55 @@ class WarehouseReport(Report):
|
|||
stock_context['locations'] = [l.id]
|
||||
with Transaction().set_context(stock_context):
|
||||
prdts = Product.search(dom_products, order=[('code', 'ASC')])
|
||||
p = [p.id for p in prdts]
|
||||
products_supplier = ProductsSupplier.search([
|
||||
('product', 'in', p)])
|
||||
prod_sup = dict((p.product.id, p.party.name) for p in products_supplier)
|
||||
# p = [p.template.id for p in prdts]
|
||||
# products_supplier = ProductsSupplier.search([
|
||||
# ('template', 'in', p)])
|
||||
suppliers = {}
|
||||
if data['group_by_supplier']:
|
||||
for p in prdts:
|
||||
if not p.template.product_suppliers:
|
||||
continue
|
||||
sup = p.template.product_suppliers[0].party
|
||||
sup_id = sup.id
|
||||
try:
|
||||
suppliers[sup_id]['products'].append(p)
|
||||
suppliers[sup_id]['total_amount'].append(p.cost_value)
|
||||
except:
|
||||
suppliers[sup_id] = {}
|
||||
suppliers[sup_id]['products'] = [p]
|
||||
suppliers[sup_id]['party'] = sup
|
||||
suppliers[sup_id]['total_amount'] = [p.cost_value]
|
||||
total_amount = sum([p.cost_value for p in prdts if p.cost_value])
|
||||
values[l.id] = {
|
||||
'name': l.name,
|
||||
'products': prdts,
|
||||
'suppliers': suppliers.values(),
|
||||
'total_amount': total_amount
|
||||
}
|
||||
products = values.values()
|
||||
else:
|
||||
with Transaction().set_context(stock_context):
|
||||
products = Product.search(dom_products, order=[('code', 'ASC')])
|
||||
p = [p.id for p in products]
|
||||
total_amount = sum([p.cost_value for p in products if p.cost_value])
|
||||
products_supplier = ProductsSupplier.search([
|
||||
('product', 'in', p)])
|
||||
prod_sup = dict((p.product.id, p.party.name) for p in products_supplier)
|
||||
|
||||
if data['only_minimal_level']:
|
||||
products = [p for p in products if p.quantity <= min_quantities[p.id]]
|
||||
total_amount = sum([p.cost_value for p in products if p.cost_value])
|
||||
suppliers = {}
|
||||
if data['group_by_supplier']:
|
||||
for p in products:
|
||||
if not p.template.product_suppliers:
|
||||
continue
|
||||
sup = p.template.product_suppliers[0].party
|
||||
sup_id = sup.id
|
||||
try:
|
||||
suppliers[sup_id]['products'].append(p)
|
||||
suppliers[sup_id]['total_amount'].append(p.cost_value)
|
||||
except:
|
||||
suppliers[sup_id] = {}
|
||||
suppliers[sup_id]['products'] = [p]
|
||||
suppliers[sup_id]['party'] = sup
|
||||
suppliers[sup_id]['total_amount'] = [p.cost_value]
|
||||
products = suppliers.values()
|
||||
|
||||
cursor = Transaction().connection.cursor()
|
||||
query = "select distinct on(p.id) p.id, t.name, p.code, s.effective_date from product_product as p right join stock_move as s on p.id=s.product join product_template as t on p.template=t.id where s.shipment ilike 'stock.shipment.in,%' and state='done' order by p.id, s.effective_date DESC;"
|
||||
|
@ -438,10 +461,9 @@ class WarehouseReport(Report):
|
|||
last_purchase[row[0]] = row_dict
|
||||
|
||||
report_context['group_by_location'] = data['group_by_location']
|
||||
report_context['group_by_supplier'] = data['group_by_supplier']
|
||||
report_context['records'] = products
|
||||
report_context['prod_sup'] = prod_sup
|
||||
report_context['total_amount'] = total_amount
|
||||
report_context['supplier'] = supplier
|
||||
report_context['last_purchase'] = last_purchase
|
||||
report_context['location'] = data['location_names']
|
||||
report_context['stock_date_end'] = data['to_date']
|
||||
|
|
|
@ -8,15 +8,16 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="to_date"/>
|
||||
<label name="category"/>
|
||||
<field name="category"/>
|
||||
<label name="supplier"/>
|
||||
<field name="supplier"/>
|
||||
<group colspan="3" col="-1" id="checkboxes">
|
||||
<label name="only_minimal_level"/>
|
||||
<field name="only_minimal_level" xexpand="0" width="25"/>
|
||||
<label name="group_by_location"/>
|
||||
<field name="group_by_location" xexpand="0" width="25"/>
|
||||
<label name="group_by_supplier"/>
|
||||
<field name="group_by_supplier" xexpand="0" width="25"/>
|
||||
<label name="zero_quantity"/>
|
||||
<field name="zero_quantity" xexpand="0" width="25"/>
|
||||
</group>
|
||||
<field name="locations" colspan="4"/>
|
||||
<field name="suppliers" colspan="4"/>
|
||||
</form>
|
||||
|
|
BIN
warehouse.fods
BIN
warehouse.fods
Binary file not shown.
Loading…
Reference in a new issue