Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.56 KB | None | 0 0
  1. class report_fattura_parser(report_sxw.rml_parse):
  2.     def __init__(self, cr, uid, name, context):
  3.         super(report_fattura_parser, self).__init__(cr, uid, name, context=context)
  4.         perc = os.path.dirname(os.path.abspath(__file__))
  5.         css_bootstrap = os.path.join(perc, 'css', 'bootstrap.min.css')
  6.         css_personal = os.path.join(perc, 'css', 'personal.css')
  7.         self.localcontext.update({
  8.             'time': time,
  9.             'cr':cr,
  10.             'uid': uid,
  11.             'css_bootstrap': css_bootstrap,
  12.             'css_personal': css_personal,
  13.             'invoice_lines': self.invoice_lines,
  14.             })
  15.         self.context = context
  16.  
  17.     def invoice_lines(self, invoice):
  18.         result = []
  19.         sub_total = {}
  20.         info = []
  21.         res = {}
  22.         list_in_seq = {}
  23.         ids = self.pool.get('account.invoice.line').search(self.cr, self.uid, [('invoice_id', '=', invoice.id)])
  24.         ids.sort()
  25.         for id in range(0, len(ids)):
  26.             info = self.pool.get('account.invoice.line').browse(self.cr, self.uid, ids[id], self.context.copy())
  27.             list_in_seq[info] = info.sequence
  28.         i = 1
  29.         j = 0
  30.         final=sorted(list_in_seq.items(), lambda x, y: cmp(x[1], y[1]))
  31.         invoice_list = [x[0] for x in final]
  32.         sum_flag = {}
  33.         sum_flag[j] = -1
  34.         for entry in invoice_list:
  35.             res = {}
  36.             if entry.state == 'article':
  37.                 self.cr.execute('select tax_id from account_invoice_line_tax where invoice_line_id=%s', (entry.id,))
  38.                 tax_ids = self.cr.fetchall()
  39.                 if tax_ids == []:
  40.                     res['tax_types'] = ''
  41.                     res['tax_amounts'] = ''
  42.                 else:
  43.                     tax_names_dict = {}
  44.                     tax_amount_dict = {}
  45.                     for item in range(0, len(tax_ids)):
  46.                         self.cr.execute('select name, amount from account_tax where id=%s', (tax_ids[item][0],))
  47.                         type = self.cr.fetchone()
  48.                         tax_names_dict[item] = type[0]
  49.                         tax_amount_dict[item] = type[1]
  50.                     tax_names = ','.join([tax_names_dict[x] for x in range(0, len(tax_names_dict))])
  51.                     tax_amounts = [tax_amount_dict[x] for x in range(0, len(tax_amount_dict))]
  52.                     res['tax_types'] = tax_names
  53.                     res['tax_amounts'] = tax_amounts
  54.                 res['name'] = entry.name
  55.                 res['quantity'] = self.formatLang(entry.quantity, digits=self.get_digits(dp='Account'))
  56.                 res['price_unit'] = self.formatLang(entry.price_unit, digits=self.get_digits(dp='Account'))
  57.                 res['discount'] = self.formatLang(entry.discount, digits=self.get_digits(dp='Account'))
  58.                 res['price_subtotal'] = self.formatLang(entry.price_subtotal, digits=self.get_digits(dp='Account'))
  59.                 sub_total[i] = entry.price_subtotal
  60.                 i = i + 1
  61.                 res['note'] = entry.note
  62.                 res['currency'] = invoice.currency_id.symbol
  63.                 res['type'] = entry.state
  64.  
  65.                 if entry.uos_id.id == False:
  66.                     res['uos'] = ''
  67.                 else:
  68.                     uos_name = self.pool.get('product.uom').read(self.cr, self.uid, entry.uos_id.id, ['name'], self.context.copy())
  69.                     res['uos'] = uos_name['name']
  70.             else:
  71.                 res['quantity'] = 0
  72.                 res['price_unit'] = ''
  73.                 res['discount'] = ''
  74.                 res['tax_types'] = ''
  75.                 res['tax_amounts'] = ''
  76.                 res['type'] = entry.state
  77.                 res['note'] = entry.note
  78.                 res['uos'] = ''
  79.  
  80.                 if entry.state == 'subtotal':
  81.                     res['name'] = entry.name
  82.                     sum = 0
  83.                     sum_id = 0
  84.                     if sum_flag[j] == -1:
  85.                         temp = 1
  86.                     else:
  87.                         temp = sum_flag[j]
  88.  
  89.                     for sum_id in range(temp, len(sub_total)+1):
  90.                         sum += sub_total[sum_id]
  91.                     sum_flag[j+1] = sum_id +1
  92.  
  93.                     j = j + 1
  94.                     res['price_subtotal'] = "%.2f" % (sum)
  95.                     res['currency'] = invoice.currency_id.symbol
  96.                 elif entry.state == 'title':
  97.                     res['name'] = entry.name
  98.                     res['price_subtotal'] = ''
  99.                     res['currency'] = ''
  100.                 elif entry.state == 'text':
  101.                     res['name'] = entry.name
  102.                     res['price_subtotal'] = ''
  103.                     res['currency'] = ''
  104.                 elif entry.state == 'line':
  105.                     res['quantity'] = '___'
  106.                     res['price_unit'] = '___'
  107.                     res['discount'] = '___'
  108.                     res['tax_types'] = '___'
  109.                     res['uos'] = '__'
  110.                     res['name'] = '_______________'
  111.                     res['price_subtotal'] = '___'
  112.                     res['currency'] = '___'
  113.                 elif entry.state == 'break':
  114.                     res['type'] = entry.state
  115.                     res['name'] = entry.name
  116.                     res['price_subtotal'] = ''
  117.                     res['currency'] = ''
  118.                 else:
  119.                     res['name'] = entry.name
  120.                     res['price_subtotal'] = ''
  121.                     res['currency'] = invoice.currency_id.symbol
  122.  
  123.             result.append(res)
  124.         return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement