|
@ -28,6 +28,7 @@ _logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
_ir_translation_name = 'nov.account.journal.print' |
|
|
_ir_translation_name = 'nov.account.journal.print' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class nov_journal_print(report_sxw.rml_parse): |
|
|
class nov_journal_print(report_sxw.rml_parse): |
|
|
|
|
|
|
|
|
def set_context(self, objects, data, ids, report_type=None): |
|
|
def set_context(self, objects, data, ids, report_type=None): |
|
@ -104,8 +105,7 @@ class nov_journal_print(report_sxw.rml_parse): |
|
|
if ids_journal_period: |
|
|
if ids_journal_period: |
|
|
self.cr.execute( |
|
|
self.cr.execute( |
|
|
'update account_journal_period set state=%s where journal_id=%s and period_id=%s and state=%s', |
|
|
'update account_journal_period set state=%s where journal_id=%s and period_id=%s and state=%s', |
|
|
('printed', journal_id, period_id, 'draft') |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
('printed', journal_id, period_id, 'draft')) |
|
|
else: |
|
|
else: |
|
|
self.pool.get('account.journal.period').create(self.cr, self.uid, { |
|
|
self.pool.get('account.journal.period').create(self.cr, self.uid, { |
|
|
'name': (journal.code or journal.name) + ':' + (period.name or ''), |
|
|
'name': (journal.code or journal.name) + ':' + (period.name or ''), |
|
@ -121,60 +121,59 @@ class nov_journal_print(report_sxw.rml_parse): |
|
|
|
|
|
|
|
|
select_extra, join_extra, where_extra = j_obj._report_xls_query_extra(self.cr, self.uid, self.context) |
|
|
select_extra, join_extra, where_extra = j_obj._report_xls_query_extra(self.cr, self.uid, self.context) |
|
|
|
|
|
|
|
|
self.cr.execute("SELECT l.move_id AS move_id, l.id AS aml_id, " \ |
|
|
|
|
|
"am.name AS move_name, coalesce(am.ref,'') AS move_ref, am.date AS move_date, " \ |
|
|
|
|
|
"aa.id AS account_id, aa.code AS acc_code, " \ |
|
|
|
|
|
"coalesce(rp.name,'') AS partner_name, coalesce(rp.ref,'') AS partner_ref, rp.id AS partner_id, " \ |
|
|
|
|
|
"coalesce(l.name,'') AS aml_name, " \ |
|
|
|
|
|
"l.date_maturity AS date_maturity, " \ |
|
|
|
|
|
"coalesce(ap.code, ap.name) AS period, " \ |
|
|
|
|
|
"coalesce(atc.code,'') AS tax_code, atc.id AS tax_code_id, coalesce(l.tax_amount,0.0) AS tax_amount, " \ |
|
|
|
|
|
"coalesce(l.debit,0.0) AS debit, coalesce(l.credit,0.0) AS credit, " \ |
|
|
|
|
|
"coalesce(amr.name,'') AS reconcile, coalesce(amrp.name,'') AS reconcile_partial, " \ |
|
|
|
|
|
"coalesce(l.amount_currency,0.0) AS amount_currency, " \ |
|
|
|
|
|
"rc.id AS currency_id, rc.name AS currency_name, rc.symbol AS currency_symbol, " \ |
|
|
|
|
|
"coalesce(ai.internal_number,'-') AS inv_number, coalesce(abs.name,'-') AS st_number, coalesce(av.number,'-') AS voucher_number " \ |
|
|
|
|
|
+ select_extra + \ |
|
|
|
|
|
"FROM account_move_line l " \ |
|
|
|
|
|
"INNER JOIN account_move am ON l.move_id = am.id " \ |
|
|
|
|
|
"INNER JOIN account_account aa ON l.account_id = aa.id " \ |
|
|
|
|
|
"INNER JOIN account_period ap ON l.period_id = ap.id " \ |
|
|
|
|
|
"LEFT OUTER JOIN account_invoice ai ON ai.move_id = am.id " \ |
|
|
|
|
|
"LEFT OUTER JOIN account_voucher av ON av.move_id = am.id " \ |
|
|
|
|
|
"LEFT OUTER JOIN account_bank_statement abs ON l.statement_id = abs.id " \ |
|
|
|
|
|
"LEFT OUTER JOIN res_partner rp ON l.partner_id = rp.id " \ |
|
|
|
|
|
"LEFT OUTER JOIN account_tax_code atc ON l.tax_code_id = atc.id " \ |
|
|
|
|
|
"LEFT OUTER JOIN account_move_reconcile amr ON l.reconcile_id = amr.id " \ |
|
|
|
|
|
"LEFT OUTER JOIN account_move_reconcile amrp ON l.reconcile_partial_id = amrp.id " \ |
|
|
|
|
|
"LEFT OUTER JOIN res_currency rc ON l.currency_id = rc.id " \ |
|
|
|
|
|
+ join_extra + \ |
|
|
|
|
|
"WHERE l.period_id IN %s AND l.journal_id = %s " \ |
|
|
|
|
|
"AND am.state IN %s " \ |
|
|
|
|
|
+ where_extra + \ |
|
|
|
|
|
|
|
|
self.cr.execute("SELECT l.move_id AS move_id, l.id AS aml_id, " |
|
|
|
|
|
"am.name AS move_name, coalesce(am.ref,'') AS move_ref, am.date AS move_date, " |
|
|
|
|
|
"aa.id AS account_id, aa.code AS acc_code, " |
|
|
|
|
|
"coalesce(rp.name,'') AS partner_name, coalesce(rp.ref,'') AS partner_ref, rp.id AS partner_id, " |
|
|
|
|
|
"coalesce(l.name,'') AS aml_name, " |
|
|
|
|
|
"l.date_maturity AS date_maturity, " |
|
|
|
|
|
"coalesce(ap.code, ap.name) AS period, " |
|
|
|
|
|
"coalesce(atc.code,'') AS tax_code, atc.id AS tax_code_id, coalesce(l.tax_amount,0.0) AS tax_amount, " |
|
|
|
|
|
"coalesce(l.debit,0.0) AS debit, coalesce(l.credit,0.0) AS credit, " |
|
|
|
|
|
"coalesce(amr.name,'') AS reconcile, coalesce(amrp.name,'') AS reconcile_partial, " |
|
|
|
|
|
"coalesce(l.amount_currency,0.0) AS amount_currency, " |
|
|
|
|
|
"rc.id AS currency_id, rc.name AS currency_name, rc.symbol AS currency_symbol, " |
|
|
|
|
|
"coalesce(ai.internal_number,'-') AS inv_number, coalesce(abs.name,'-') AS st_number, coalesce(av.number,'-') AS voucher_number " |
|
|
|
|
|
+ select_extra + |
|
|
|
|
|
"FROM account_move_line l " |
|
|
|
|
|
"INNER JOIN account_move am ON l.move_id = am.id " |
|
|
|
|
|
"INNER JOIN account_account aa ON l.account_id = aa.id " |
|
|
|
|
|
"INNER JOIN account_period ap ON l.period_id = ap.id " |
|
|
|
|
|
"LEFT OUTER JOIN account_invoice ai ON ai.move_id = am.id " |
|
|
|
|
|
"LEFT OUTER JOIN account_voucher av ON av.move_id = am.id " |
|
|
|
|
|
"LEFT OUTER JOIN account_bank_statement abs ON l.statement_id = abs.id " |
|
|
|
|
|
"LEFT OUTER JOIN res_partner rp ON l.partner_id = rp.id " |
|
|
|
|
|
"LEFT OUTER JOIN account_tax_code atc ON l.tax_code_id = atc.id " |
|
|
|
|
|
"LEFT OUTER JOIN account_move_reconcile amr ON l.reconcile_id = amr.id " |
|
|
|
|
|
"LEFT OUTER JOIN account_move_reconcile amrp ON l.reconcile_partial_id = amrp.id " |
|
|
|
|
|
"LEFT OUTER JOIN res_currency rc ON l.currency_id = rc.id " |
|
|
|
|
|
+ join_extra + |
|
|
|
|
|
"WHERE l.period_id IN %s AND l.journal_id = %s " |
|
|
|
|
|
"AND am.state IN %s " |
|
|
|
|
|
+ where_extra + |
|
|
"ORDER BY " + self.sort_selection + ", move_date, move_id, acc_code", |
|
|
"ORDER BY " + self.sort_selection + ", move_date, move_id, acc_code", |
|
|
(tuple(period_ids), journal_id, tuple(self.move_states)) |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
(tuple(period_ids), journal_id, tuple(self.move_states))) |
|
|
lines = self.cr.dictfetchall() |
|
|
lines = self.cr.dictfetchall() |
|
|
|
|
|
|
|
|
# add reference of corresponding origin document |
|
|
# add reference of corresponding origin document |
|
|
if journal.type in ['sale', 'sale_refund', 'purchase', 'purchase_refund']: |
|
|
|
|
|
map(lambda x: x.update({'docname' : (_('Invoice') + ': ' + x['inv_number']) or (_('Voucher') + ': ' + x['voucher_number']) or '-'}), lines) |
|
|
|
|
|
elif journal.type in ['bank', 'cash']: |
|
|
|
|
|
map(lambda x: x.update({'docname' : (_('Statement') + ': ' + x['st_number']) or (_('Voucher') + ': ' + x['voucher_number']) or '-'}), lines) |
|
|
|
|
|
|
|
|
if journal.type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'): |
|
|
|
|
|
[x.update({'docname': (_('Invoice') + ': ' + x['inv_number']) or (_('Voucher') + ': ' + x['voucher_number']) or '-'}) for x in lines] |
|
|
|
|
|
elif journal.type in ('bank', 'cash'): |
|
|
|
|
|
[x.update({'docname': (_('Statement') + ': ' + x['st_number']) or (_('Voucher') + ': ' + x['voucher_number']) or '-'}) for x in lines] |
|
|
else: |
|
|
else: |
|
|
code_string = j_obj._report_xls_document_extra(self.cr, self.uid, self.context) |
|
|
code_string = j_obj._report_xls_document_extra(self.cr, self.uid, self.context) |
|
|
#_logger.warn('code_string= %s', code_string) |
|
|
#_logger.warn('code_string= %s', code_string) |
|
|
map(lambda x: x.update({'docname' : eval(code_string) or '-'}), lines) |
|
|
|
|
|
|
|
|
[x.update({'docname': eval(code_string) or '-'}) for x in lines] |
|
|
|
|
|
|
|
|
# format debit, credit, amount_currency for pdf report |
|
|
# format debit, credit, amount_currency for pdf report |
|
|
if self.display_currency and self.report_type == 'pdf': |
|
|
if self.display_currency and self.report_type == 'pdf': |
|
|
curr_obj = self.pool.get('res.currency') |
|
|
curr_obj = self.pool.get('res.currency') |
|
|
map(lambda x: x.update({ |
|
|
|
|
|
|
|
|
[x.update({ |
|
|
'amount1': self.formatLang(x['debit'] - x['credit']), |
|
|
'amount1': self.formatLang(x['debit'] - x['credit']), |
|
|
'amount2': self.formatLang(x['amount_currency'], monetary=True, currency_obj=curr_obj.browse(self.cr, self.uid, x['currency_id'])) |
|
|
|
|
|
}), lines) |
|
|
|
|
|
|
|
|
'amount2': self.formatLang(x['amount_currency'], monetary=True, currency_obj=curr_obj.browse(self.cr, self.uid, x['currency_id'])), |
|
|
|
|
|
}) for x in lines] |
|
|
else: |
|
|
else: |
|
|
map(lambda x: x.update({'amount1': self.formatLang(x['debit']), 'amount2': self.formatLang(x['credit'])}), lines) |
|
|
|
|
|
|
|
|
[x.update({'amount1': self.formatLang(x['debit']), 'amount2': self.formatLang(x['credit'])}) for x in lines] |
|
|
|
|
|
|
|
|
# group lines |
|
|
# group lines |
|
|
if self.group_entries: |
|
|
if self.group_entries: |
|
@ -183,7 +182,7 @@ class nov_journal_print(report_sxw.rml_parse): |
|
|
# insert a flag in every move_line to indicate the end of a move |
|
|
# insert a flag in every move_line to indicate the end of a move |
|
|
# this flag will be used to draw a full line between moves |
|
|
# this flag will be used to draw a full line between moves |
|
|
for cnt in range(len(lines) - 1): |
|
|
for cnt in range(len(lines) - 1): |
|
|
if lines[cnt]['move_id'] <> lines[cnt+1]['move_id']: |
|
|
|
|
|
|
|
|
if lines[cnt]['move_id'] != lines[cnt + 1]['move_id']: |
|
|
lines[cnt]['draw_line'] = 1 |
|
|
lines[cnt]['draw_line'] = 1 |
|
|
else: |
|
|
else: |
|
|
lines[cnt]['draw_line'] = 0 |
|
|
lines[cnt]['draw_line'] = 0 |
|
@ -216,7 +215,7 @@ class nov_journal_print(report_sxw.rml_parse): |
|
|
grouped_lines = [lines_in[0]] |
|
|
grouped_lines = [lines_in[0]] |
|
|
move_id = lines_in[0]['move_id'] |
|
|
move_id = lines_in[0]['move_id'] |
|
|
line_cnt = len(lines_in) |
|
|
line_cnt = len(lines_in) |
|
|
for i in range(1,line_cnt): |
|
|
|
|
|
|
|
|
for i, line in enumerate(lines_in): |
|
|
line = lines_in[i] |
|
|
line = lines_in[i] |
|
|
if line['move_id'] == move_id: |
|
|
if line['move_id'] == move_id: |
|
|
grouped_lines.append(line) |
|
|
grouped_lines.append(line) |
|
@ -238,8 +237,8 @@ class nov_journal_print(report_sxw.rml_parse): |
|
|
fiscalyear = object[1] |
|
|
fiscalyear = object[1] |
|
|
period_ids = [x.id for x in fiscalyear.period_ids] |
|
|
period_ids = [x.id for x in fiscalyear.period_ids] |
|
|
self.cr.execute( |
|
|
self.cr.execute( |
|
|
"SELECT distinct tax_code_id FROM account_move_line l " \ |
|
|
|
|
|
"INNER JOIN account_move am ON l.move_id = am.id " \ |
|
|
|
|
|
|
|
|
"SELECT distinct tax_code_id FROM account_move_line l " |
|
|
|
|
|
"INNER JOIN account_move am ON l.move_id = am.id " |
|
|
"WHERE l.period_id in %s AND l.journal_id=%s AND l.tax_code_id IS NOT NULL AND am.state IN %s", |
|
|
"WHERE l.period_id in %s AND l.journal_id=%s AND l.tax_code_id IS NOT NULL AND am.state IN %s", |
|
|
(tuple(period_ids), journal_id, tuple(self.move_states))) |
|
|
(tuple(period_ids), journal_id, tuple(self.move_states))) |
|
|
ids = map(lambda x: x[0], self.cr.fetchall()) |
|
|
ids = map(lambda x: x[0], self.cr.fetchall()) |
|
|