Refactory report

This commit is contained in:
Oscar 2021-09-18 11:12:48 -05:00
parent a49d8a3cda
commit 4f3f1c2170
8 changed files with 57 additions and 18 deletions

View File

@ -2,7 +2,9 @@
# this repository contains the full copyright notices and license terms.
from datetime import date
from decimal import Decimal
from operator import itemgetter
from sql import Table
from trytond.pool import Pool, PoolMeta
from trytond.wizard import Wizard, StateTransition, StateView, Button, StateReport
from trytond.transaction import Transaction
@ -10,6 +12,12 @@ from trytond.model import ModelView, fields
from trytond.report import Report
from trytond.pyson import Eval
type_shipment = {
'out': 'Envio a Clientes',
'in': 'Envio de Proveedor',
'internal': 'Envio Interno',
}
class ShipmentIn(metaclass=PoolMeta):
'Shipment In'
@ -287,30 +295,62 @@ class ShipmentDetailedReport(Report):
report_context = super().get_context(records, header, data)
pool = Pool()
company = Transaction().context.get('company.rec_name')
model = 'stock.shipment.' + data['type_shipment']
ModelShipment = pool.get(model)
Move = pool.get('stock.move')
Product = pool.get('product.product')
dom_shipment = [
('company', '=', data['company']),
('effective_date', '>=', data['start_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')]
)
shipments = [model + ',' + str(sh['id']) for sh in shipments]
_records = []
for s in shipments:
for m in s.moves:
value = {
'oc': s.to_location.parent.operation_center.name if s.to_location.parent.operation_center else '',
'move': m,
'shipment': s
}
_records.append(value)
fields_names = [
'product.account_category.name', 'product.name', 'product.cost_price',
'quantity',
]
moves = Move.search_read(
('shipment', 'in', shipments),
fields_names=fields_names
)
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['data'] = data
report_context['kind'] = type_shipment[data['type_shipment']]
return report_context

Binary file not shown.

View File

@ -25,7 +25,7 @@ this repository contains the full copyright notices and license terms. -->
<field name="name">Move by Product</field>
<field name="model"></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="translatable">False</field>
</record>
@ -49,7 +49,7 @@ this repository contains the full copyright notices and license terms. -->
<field name="name">Warehouse</field>
<field name="model"></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="translatable">False</field>
</record>
@ -69,7 +69,7 @@ this repository contains the full copyright notices and license terms. -->
<field name="name">Warehouse Detailed</field>
<field name="model"></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="translatable">False</field>
</record>
@ -89,7 +89,7 @@ this repository contains the full copyright notices and license terms. -->
<field name="name">Print Products</field>
<field name="model"></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="translatable">False</field>
</record>

View File

@ -3,12 +3,11 @@
this repository contains the full copyright notices and license terms. -->
<form>
<label name="company"/>
<field name="company"/>
<field name="company" widget="selection"/>
<label name="type_shipment"/>
<field name="type_shipment"/>
<label name="start_date"/>
<field name="start_date"/>
<label name="end_date"/>
<field name="end_date"/>
</form>