Refactory report
This commit is contained in:
parent
a49d8a3cda
commit
4f3f1c2170
64
shipment.py
64
shipment.py
|
@ -2,7 +2,9 @@
|
||||||
# this repository contains the full copyright notices and license terms.
|
# this repository contains the full copyright notices and license terms.
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
from operator import itemgetter
|
||||||
from sql import Table
|
from sql import Table
|
||||||
|
|
||||||
from trytond.pool import Pool, PoolMeta
|
from trytond.pool import Pool, PoolMeta
|
||||||
from trytond.wizard import Wizard, StateTransition, StateView, Button, StateReport
|
from trytond.wizard import Wizard, StateTransition, StateView, Button, StateReport
|
||||||
from trytond.transaction import Transaction
|
from trytond.transaction import Transaction
|
||||||
|
@ -10,6 +12,12 @@ from trytond.model import ModelView, fields
|
||||||
from trytond.report import Report
|
from trytond.report import Report
|
||||||
from trytond.pyson import Eval
|
from trytond.pyson import Eval
|
||||||
|
|
||||||
|
type_shipment = {
|
||||||
|
'out': 'Envio a Clientes',
|
||||||
|
'in': 'Envio de Proveedor',
|
||||||
|
'internal': 'Envio Interno',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class ShipmentIn(metaclass=PoolMeta):
|
class ShipmentIn(metaclass=PoolMeta):
|
||||||
'Shipment In'
|
'Shipment In'
|
||||||
|
@ -287,30 +295,62 @@ class ShipmentDetailedReport(Report):
|
||||||
report_context = super().get_context(records, header, data)
|
report_context = super().get_context(records, header, data)
|
||||||
|
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
|
company = Transaction().context.get('company.rec_name')
|
||||||
model = 'stock.shipment.' + data['type_shipment']
|
model = 'stock.shipment.' + data['type_shipment']
|
||||||
ModelShipment = pool.get(model)
|
ModelShipment = pool.get(model)
|
||||||
|
Move = pool.get('stock.move')
|
||||||
|
Product = pool.get('product.product')
|
||||||
dom_shipment = [
|
dom_shipment = [
|
||||||
('company', '=', data['company']),
|
('company', '=', data['company']),
|
||||||
('effective_date', '>=', data['start_date']),
|
('effective_date', '>=', data['start_date']),
|
||||||
('effective_date', '<=', data['end_date'])
|
('effective_date', '<=', data['end_date'])
|
||||||
]
|
]
|
||||||
shipments = ModelShipment.search(dom_shipment,
|
fields_names = ['id']
|
||||||
|
shipments = ModelShipment.search_read(dom_shipment,
|
||||||
|
fields_names=fields_names,
|
||||||
order=[('effective_date', 'ASC')]
|
order=[('effective_date', 'ASC')]
|
||||||
)
|
)
|
||||||
|
shipments = [model + ',' + str(sh['id']) for sh in shipments]
|
||||||
|
|
||||||
_records = []
|
fields_names = [
|
||||||
for s in shipments:
|
'product.account_category.name', 'product.name', 'product.cost_price',
|
||||||
for m in s.moves:
|
'quantity',
|
||||||
value = {
|
]
|
||||||
'oc': s.to_location.parent.operation_center.name if s.to_location.parent.operation_center else '',
|
moves = Move.search_read(
|
||||||
'move': m,
|
('shipment', 'in', shipments),
|
||||||
'shipment': s
|
fields_names=fields_names
|
||||||
}
|
)
|
||||||
_records.append(value)
|
|
||||||
|
|
||||||
report_context['records'] = _records
|
dgetter = itemgetter('product.', 'quantity')
|
||||||
|
product_browse = Product.browse
|
||||||
|
for m in moves:
|
||||||
|
product, quantity = dgetter(m)
|
||||||
|
product_, = product_browse([product['id']])
|
||||||
|
try:
|
||||||
|
# FIXME
|
||||||
|
# oc = s.to_location.parent.operation_center.name
|
||||||
|
pass
|
||||||
|
except:
|
||||||
|
oc = ''
|
||||||
|
|
||||||
|
cost_price = product['cost_price']
|
||||||
|
category = product.get('account_category.', '')
|
||||||
|
if category:
|
||||||
|
category = category['name']
|
||||||
|
|
||||||
|
m.update({
|
||||||
|
'oc': '',
|
||||||
|
'product': product['name'],
|
||||||
|
'cost_price': cost_price,
|
||||||
|
'category': category,
|
||||||
|
'cost_base': float(cost_price) * quantity,
|
||||||
|
'cost_w_tax': float(product_.cost_price_taxed) * quantity,
|
||||||
|
})
|
||||||
|
|
||||||
|
report_context['records'] = moves
|
||||||
|
report_context['company'] = company
|
||||||
report_context['Decimal'] = Decimal
|
report_context['Decimal'] = Decimal
|
||||||
report_context['data'] = data
|
report_context['kind'] = type_shipment[data['type_shipment']]
|
||||||
return report_context
|
return report_context
|
||||||
|
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -25,7 +25,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||||
<field name="name">Move by Product</field>
|
<field name="name">Move by Product</field>
|
||||||
<field name="model"></field>
|
<field name="model"></field>
|
||||||
<field name="report_name">stock_co.move_by_product</field>
|
<field name="report_name">stock_co.move_by_product</field>
|
||||||
<field name="report">stock_co/move_by_products.ods</field>
|
<field name="report">stock_co/move_by_products.fods</field>
|
||||||
<field name="template_extension">ods</field>
|
<field name="template_extension">ods</field>
|
||||||
<field name="translatable">False</field>
|
<field name="translatable">False</field>
|
||||||
</record>
|
</record>
|
||||||
|
@ -49,7 +49,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||||
<field name="name">Warehouse</field>
|
<field name="name">Warehouse</field>
|
||||||
<field name="model"></field>
|
<field name="model"></field>
|
||||||
<field name="report_name">stock_co.warehouse_stock.report</field>
|
<field name="report_name">stock_co.warehouse_stock.report</field>
|
||||||
<field name="report">stock_co/warehouse.ods</field>
|
<field name="report">stock_co/warehouse.fods</field>
|
||||||
<field name="template_extension">ods</field>
|
<field name="template_extension">ods</field>
|
||||||
<field name="translatable">False</field>
|
<field name="translatable">False</field>
|
||||||
</record>
|
</record>
|
||||||
|
@ -69,7 +69,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||||
<field name="name">Warehouse Detailed</field>
|
<field name="name">Warehouse Detailed</field>
|
||||||
<field name="model"></field>
|
<field name="model"></field>
|
||||||
<field name="report_name">stock_co.warehouse_stock_detailed.report</field>
|
<field name="report_name">stock_co.warehouse_stock_detailed.report</field>
|
||||||
<field name="report">stock_co/warehouse_detailed.ods</field>
|
<field name="report">stock_co/warehouse_detailed.fods</field>
|
||||||
<field name="template_extension">ods</field>
|
<field name="template_extension">ods</field>
|
||||||
<field name="translatable">False</field>
|
<field name="translatable">False</field>
|
||||||
</record>
|
</record>
|
||||||
|
@ -89,7 +89,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||||
<field name="name">Print Products</field>
|
<field name="name">Print Products</field>
|
||||||
<field name="model"></field>
|
<field name="model"></field>
|
||||||
<field name="report_name">stock_co.print_products.report</field>
|
<field name="report_name">stock_co.print_products.report</field>
|
||||||
<field name="report">stock_co/products.ods</field>
|
<field name="report">stock_co/products.fods</field>
|
||||||
<field name="template_extension">ods</field>
|
<field name="template_extension">ods</field>
|
||||||
<field name="translatable">False</field>
|
<field name="translatable">False</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
|
@ -3,12 +3,11 @@
|
||||||
this repository contains the full copyright notices and license terms. -->
|
this repository contains the full copyright notices and license terms. -->
|
||||||
<form>
|
<form>
|
||||||
<label name="company"/>
|
<label name="company"/>
|
||||||
<field name="company"/>
|
<field name="company" widget="selection"/>
|
||||||
<label name="type_shipment"/>
|
<label name="type_shipment"/>
|
||||||
<field name="type_shipment"/>
|
<field name="type_shipment"/>
|
||||||
<label name="start_date"/>
|
<label name="start_date"/>
|
||||||
<field name="start_date"/>
|
<field name="start_date"/>
|
||||||
<label name="end_date"/>
|
<label name="end_date"/>
|
||||||
<field name="end_date"/>
|
<field name="end_date"/>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in New Issue