diff --git a/move_by_products.ods b/move_by_products.fods
similarity index 100%
rename from move_by_products.ods
rename to move_by_products.fods
diff --git a/products.ods b/products.fods
similarity index 100%
rename from products.ods
rename to products.fods
diff --git a/shipment.py b/shipment.py
index f0835ee..8601f52 100644
--- a/shipment.py
+++ b/shipment.py
@@ -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
diff --git a/shipment_detailed.fods b/shipment_detailed.fods
index 78ff720..5a75650 100644
Binary files a/shipment_detailed.fods and b/shipment_detailed.fods differ
diff --git a/stock.xml b/stock.xml
index 7a0fcaa..bda0787 100644
--- a/stock.xml
+++ b/stock.xml
@@ -25,7 +25,7 @@ this repository contains the full copyright notices and license terms. -->