Created
July 27, 2012 04:36
-
-
Save sharoonthomas/3186197 to your computer and use it in GitHub Desktop.
Sample CSV report for Tryton CSV Report
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CSVReportEngine(ModelView): | |
"""CSV reports for ...""" | |
_name = 'csv.report.engine' | |
def report_tracking_numbers(self, data, buffer): | |
"Tracking Numbers" | |
shipment_obj = self.pool.get('stock.shipment.out') | |
move_obj = self.pool.get('stock.move') | |
domain = [ | |
('to_location.type', '=', 'customer'), | |
('effective_date', '>=', data.get('from_date')), | |
('effective_date', '<=', data.get('to_date')), | |
('sale_line', '!=', False), | |
('state', '=', 'done'), | |
] | |
if data.get('party'): | |
domain.append(('sale_line.sale.party', '=', data['party'])) | |
move_ids = move_obj.search(domain) | |
field_names = [ | |
'Order #', # Order no as imported | |
'Effective Date', # Effective date of shipping | |
'Division', # Division from which order was placed | |
'Customer', # End customer's name | |
'Address', # Address to shich the shipment is made | |
'Product', # Name of the product in English | |
'Product Code', # Product Code | |
'Quantity', # Quantity that was shipped | |
'Shipment Tracking Number(s)', # Tracking numbers separated by ' ' | |
'Carrier(s)', # The name of the carrier | |
'SUB_NUM_PEDIDO', # The sub order# see ticket:1752 | |
] | |
csvwriter = UnicodeDictWriter(buffer, field_names) | |
csvwriter.writer.writerow(field_names) | |
for move in move_obj.browse(move_ids): | |
if move.quantity > 0: | |
tracking_numbers = ' '.join( | |
s.tracking_number for s in move.shipment_out.shipment_records | |
) | |
carriers = ' '.join( | |
s.carrier.name for s in move.shipment_out.shipment_records | |
) | |
data = { | |
'Order #': move.sale.reference, | |
'Effective Date': move.effective_date, | |
'Division': move.shipment_out.customer.name, | |
'Customer': move.sale.invoice_address.name, | |
'Address': move.shipment_out.delivery_address.rec_name, | |
'Product': move.product.name, | |
'Product Code': move.product.code, | |
'Quantity': move.quantity, | |
'Shipment Tracking Number(s)': tracking_numbers, | |
'Carrier(s)': carriers, | |
'SUB_NUM_PEDIDO': move.sale_line.note, | |
} | |
csvwriter.writerow(data) | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment