From e28a6ede8ac9a3eaca7607f8942d0b719f1f4f5a Mon Sep 17 00:00:00 2001 From: Chinmayi Vyas Date: Wed, 30 May 2018 15:07:48 +0530 Subject: [PATCH] [IMP]GST:change field label, fiscal position->Nature of Transection,changes gst excel report format --- addons/l10n_in_gst/models/account_invoice.py | 11 +++++++-- addons/l10n_in_gst/models/res_partner.py | 7 ++++++ addons/l10n_in_gst/report/gst_report.py | 24 +++++++++++++++++--- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/addons/l10n_in_gst/models/account_invoice.py b/addons/l10n_in_gst/models/account_invoice.py index a49e2ed2..ef40bf6f 100644 --- a/addons/l10n_in_gst/models/account_invoice.py +++ b/addons/l10n_in_gst/models/account_invoice.py @@ -43,9 +43,15 @@ class AccountInvoice(models.Model): ('composite', 'Composite'), ('volunteer', 'Volunteer')], string='GST Type', copy=False) partner_location = fields.Selection( - [('inter_state', 'Inter State'), ('intra_state', 'intra State'), + [('inter_state', 'Inter State'), ('intra_state', 'Intra State'), ('inter_country', 'Inter Country')], related='partner_id.partner_location', string="Partner Location") + fiscal_position_id = fields.Many2one('account.fiscal.position', + string='Nature of Transaction', + oldname='fiscal_position', + readonly=True, + states={ + 'draft': [('readonly', False)]}) @api.onchange('partner_id', 'company_id') def _onchange_partner_id(self): @@ -54,11 +60,12 @@ class AccountInvoice(models.Model): self.partner_id.partner_location = \ self.partner_id._get_partner_location_details(self.company_id) + @api.onchange('fiscal_position_id') def _onchange_fiscal_position_id(self): """ Onchange of Fiscal Position update tax values in invoice lines. """ for line in self.invoice_line_ids: - line._onchange_product_id() + line._set_taxes() @api.multi def action_move_create(self): diff --git a/addons/l10n_in_gst/models/res_partner.py b/addons/l10n_in_gst/models/res_partner.py index 3c08501b..c5e641ba 100644 --- a/addons/l10n_in_gst/models/res_partner.py +++ b/addons/l10n_in_gst/models/res_partner.py @@ -19,6 +19,13 @@ class Partner(models.Model): ('intra_state', 'intra State'), ('inter_country', 'Inter Country') ], "Partner Location") + property_account_position_id = fields.Many2one( + 'account.fiscal.position', + company_dependent=True, + string="Nature of Transaction", + help="The fiscal position will determine taxes and accounts " + "used for the partner.", + oldname="property_account_position") @api.multi @api.constrains('vat', 'state_id') diff --git a/addons/l10n_in_gst/report/gst_report.py b/addons/l10n_in_gst/report/gst_report.py index 9ff8ad63..68aff838 100644 --- a/addons/l10n_in_gst/report/gst_report.py +++ b/addons/l10n_in_gst/report/gst_report.py @@ -2,8 +2,10 @@ from io import BytesIO from datetime import datetime - +from operator import itemgetter +from itertools import groupby import xlsxwriter +from functools import reduce from flectra import api, models, _ @@ -901,6 +903,20 @@ class GSTR1Report(models.AbstractModel): self.write_data_worksheet_values(worksheet, inv_value, row, col) row += 1 + def _groupby_b2cs_inv(self, invoices): + keys = ['place_supply', 'rate'] + + return [reduce(lambda a,b: { + "place_supply":a["place_supply"], + "rate": a['rate'], "type": a['type'], + "taxable_value":a["taxable_value"]+b["taxable_value"], + "cess_amount":a["cess_amount"]+b["cess_amount"], + "ecommerce_gstin":a["ecommerce_gstin"]},list(g)) + for k, g in groupby(sorted(invoices, key=itemgetter( + *keys)), key=itemgetter(*keys)) + ] + + def sheet_b2cs(self, data, workbook, **post): """ Generate excel sheet for 'b2cs' data """ cell_format = self.cell_format(workbook=workbook, **post) @@ -909,6 +925,7 @@ class GSTR1Report(models.AbstractModel): worksheet.set_column(0, 20, 20) worksheet.protect() inv_ids_b2cs = self.get_data_b2cs(data=data, **post) + b2cs_data = self._groupby_b2cs_inv(inv_ids_b2cs) # Calculation of header summary = self.get_data_b2cs_summary(data=data, **post) row = 0 @@ -943,7 +960,7 @@ class GSTR1Report(models.AbstractModel): worksheet, invoice_header, cell_format[ 'header_cell_format'], row, col) row += 1 - for inv in inv_ids_b2cs: + for inv in b2cs_data: inv_value = [{ 'value': inv['type'], 'format': cell_format['regular_cell_format']}, @@ -1142,8 +1159,9 @@ class GSTR1Report(models.AbstractModel): invoice_header = ["GSTIN/UIN of Recipient", 'Invoice/Advance Receipt Number', 'Invoice/Advance Receipt date', + 'Note/Refund Voucher Number', 'Note/Refund Voucher date', - 'Note/Refund Voucher Number', 'Document Type', + 'Document Type', 'Reason For Issuing document', "Place Of Supply", 'Note/Refund Voucher Value', "Rate", "Taxable Value", "Cess Amount", 'Pre GST']