From ea9e8a37d6f7bc58ee5d323830310173c33ed20d Mon Sep 17 00:00:00 2001 From: Jigar Vaghela Date: Thu, 26 Sep 2019 07:13:26 +0000 Subject: [PATCH] [IMP] l10n_in*: multi GSTIN Using journal ======= Purpose ======= government rule that "GST registration should be obtained by a taxable person under GST in each of the State or Union Territory, from where the taxable supply of goods or services is made" So we managed this using journal User create journal and partner for other states After user can select journal in Sale order, Purchase order and warehouse ======== Solution ======== -Add a field on the journal to define the GSTIN -Add sale and purchase journal field in warehouse -On the SO/PO, add the journal field and based on the warehouse journal it set automatically fill if warehouse journal is set. task 1917619 --- addons/l10n_in/models/account.py | 16 +++++++++++ addons/l10n_in/models/chart_template.py | 6 ++-- .../l10n_in/views/account_journal_views.xml | 3 ++ addons/l10n_in_purchase/__init__.py | 1 + addons/l10n_in_purchase/__manifest__.py | 1 + addons/l10n_in_purchase/models/__init__.py | 5 ++++ .../l10n_in_purchase/models/account_move.py | 16 +++++++++++ .../l10n_in_purchase/models/purchase_order.py | 19 +++++++++++++ .../views/purchase_order_views.xml | 13 +++++++++ addons/l10n_in_purchase_stock/__init__.py | 4 +++ addons/l10n_in_purchase_stock/__manifest__.py | 28 +++++++++++++++++++ .../l10n_in_purchase_stock/models/__init__.py | 5 ++++ .../models/purchase_order.py | 15 ++++++++++ .../models/stock_warehouse.py | 10 +++++++ .../views/stock_warehouse_views.xml | 13 +++++++++ addons/l10n_in_sale/__init__.py | 1 + addons/l10n_in_sale/models/sale_order.py | 11 ++++++++ addons/l10n_in_sale/views/sale_views.xml | 3 ++ addons/l10n_in_sale/wizard/__init__.py | 4 +++ .../wizard/sale_make_invoice_advance.py | 14 ++++++++++ addons/l10n_in_sale_stock/__init__.py | 4 +++ addons/l10n_in_sale_stock/__manifest__.py | 28 +++++++++++++++++++ addons/l10n_in_sale_stock/models/__init__.py | 5 ++++ .../l10n_in_sale_stock/models/sale_order.py | 15 ++++++++++ .../models/stock_warehouse.py | 10 +++++++ .../views/stock_warehouse_views.xml | 13 +++++++++ 26 files changed, 261 insertions(+), 2 deletions(-) create mode 100644 addons/l10n_in_purchase/models/__init__.py create mode 100644 addons/l10n_in_purchase/models/account_move.py create mode 100644 addons/l10n_in_purchase/models/purchase_order.py create mode 100644 addons/l10n_in_purchase/views/purchase_order_views.xml create mode 100644 addons/l10n_in_purchase_stock/__init__.py create mode 100644 addons/l10n_in_purchase_stock/__manifest__.py create mode 100644 addons/l10n_in_purchase_stock/models/__init__.py create mode 100644 addons/l10n_in_purchase_stock/models/purchase_order.py create mode 100644 addons/l10n_in_purchase_stock/models/stock_warehouse.py create mode 100644 addons/l10n_in_purchase_stock/views/stock_warehouse_views.xml create mode 100644 addons/l10n_in_sale/wizard/__init__.py create mode 100644 addons/l10n_in_sale/wizard/sale_make_invoice_advance.py create mode 100644 addons/l10n_in_sale_stock/__init__.py create mode 100644 addons/l10n_in_sale_stock/__manifest__.py create mode 100644 addons/l10n_in_sale_stock/models/__init__.py create mode 100644 addons/l10n_in_sale_stock/models/sale_order.py create mode 100644 addons/l10n_in_sale_stock/models/stock_warehouse.py create mode 100644 addons/l10n_in_sale_stock/views/stock_warehouse_views.xml diff --git a/addons/l10n_in/models/account.py b/addons/l10n_in/models/account.py index b28d6a1ab33..eb10eced9b9 100644 --- a/addons/l10n_in/models/account.py +++ b/addons/l10n_in/models/account.py @@ -10,6 +10,22 @@ class AccountJournal(models.Model): # Use for filter import and export type. l10n_in_import_export = fields.Boolean("Import/Export", help="Tick this if this journal is use for Import/Export Under Indian GST.") + l10n_in_gstin_partner_id = fields.Many2one('res.partner', string="GSTIN", ondelete="restrict", help="GSTIN related to this journal. If empty then consider as company GSTIN.") + + def name_get(self): + """ + Add GSTIN number in name as suffix so user can easily find the right journal. + Used super to ensure nothing is missed. + """ + result = super().name_get() + result_dict = dict(result) + indian_journals = self.filtered(lambda j: j.company_id.country_id.code == 'IN' and + j.l10n_in_gstin_partner_id and j.l10n_in_gstin_partner_id.vat) + for journal in indian_journals: + name = result_dict[journal.id] + name += "- %s" % (journal.l10n_in_gstin_partner_id.vat) + result_dict[journal.id] = name + return list(result_dict.items()) class AccountMoveLine(models.Model): diff --git a/addons/l10n_in/models/chart_template.py b/addons/l10n_in/models/chart_template.py index 5fe711b4df7..39f3270b755 100644 --- a/addons/l10n_in/models/chart_template.py +++ b/addons/l10n_in/models/chart_template.py @@ -11,12 +11,14 @@ class AccountChartTemplate(models.Model): res = super(AccountChartTemplate, self)._prepare_all_journals(acc_template_ref, company, journals_dict=journals_dict) if self == self.env.ref('l10n_in.indian_chart_template_standard'): for journal in res: + if journal.get('type') in ('sale','purchase'): + journal['l10n_in_gstin_partner_id'] = company.partner_id.id if journal['code'] == 'INV': journal['name'] = _('Tax Invoices') res += [ - {'type': 'sale', 'name': _('Retail Invoices'), 'code': 'RETINV', 'company_id': company.id, 'show_on_dashboard': True,}, - {'type': 'sale', 'name': _('Export Invoices'), 'code': 'EXPINV', 'company_id': company.id, 'show_on_dashboard': True, 'l10n_in_import_export': True} + {'type': 'sale', 'name': _('Retail Invoices'), 'code': 'RETINV', 'company_id': company.id, 'show_on_dashboard': True, 'l10n_in_gstin_partner_id': company.partner_id.id}, + {'type': 'sale', 'name': _('Export Invoices'), 'code': 'EXPINV', 'company_id': company.id, 'show_on_dashboard': True, 'l10n_in_import_export': True, 'l10n_in_gstin_partner_id': company.partner_id.id} ] return res diff --git a/addons/l10n_in/views/account_journal_views.xml b/addons/l10n_in/views/account_journal_views.xml index 264a0e87098..01d68c9733e 100644 --- a/addons/l10n_in/views/account_journal_views.xml +++ b/addons/l10n_in/views/account_journal_views.xml @@ -11,6 +11,9 @@ + + + diff --git a/addons/l10n_in_purchase/__init__.py b/addons/l10n_in_purchase/__init__.py index 2903e8d9121..dc5e6b693d1 100644 --- a/addons/l10n_in_purchase/__init__.py +++ b/addons/l10n_in_purchase/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from . import models diff --git a/addons/l10n_in_purchase/__manifest__.py b/addons/l10n_in_purchase/__manifest__.py index 0d6e75058d9..eb5116fc954 100644 --- a/addons/l10n_in_purchase/__manifest__.py +++ b/addons/l10n_in_purchase/__manifest__.py @@ -12,6 +12,7 @@ ], 'data': [ 'views/report_purchase_order.xml', + 'views/purchase_order_views.xml', ], 'installable': True, 'application': False, diff --git a/addons/l10n_in_purchase/models/__init__.py b/addons/l10n_in_purchase/models/__init__.py new file mode 100644 index 00000000000..476326ad60b --- /dev/null +++ b/addons/l10n_in_purchase/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import purchase_order +from . import account_move diff --git a/addons/l10n_in_purchase/models/account_move.py b/addons/l10n_in_purchase/models/account_move.py new file mode 100644 index 00000000000..4587df067e7 --- /dev/null +++ b/addons/l10n_in_purchase/models/account_move.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models + + +class AccountMove(models.Model): + _inherit = 'account.move' + + @api.onchange('purchase_vendor_bill_id', 'purchase_id') + def _onchange_purchase_auto_complete(self): + if self.purchase_vendor_bill_id.purchase_order_id or self.purchase_id: + journal_id = self.purchase_vendor_bill_id.purchase_order_id.l10n_in_journal_id or self.purchase_id.l10n_in_journal_id + if journal_id: + self.journal_id = journal_id + return super()._onchange_purchase_auto_complete() diff --git a/addons/l10n_in_purchase/models/purchase_order.py b/addons/l10n_in_purchase/models/purchase_order.py new file mode 100644 index 00000000000..9cdecfb3064 --- /dev/null +++ b/addons/l10n_in_purchase/models/purchase_order.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + l10n_in_journal_id = fields.Many2one('account.journal', string="Journal", \ + states={'posted': [('readonly', True)]}, domain="[('type','=', 'purchase')]") + + @api.onchange('company_id') + def l10n_in_onchange_company_id(self): + domain = [('company_id', '=', self.company_id.id), ('type', '=', 'purchase')] + + journal = self.env['account.journal'].search(domain, limit=1) + if journal: + self.l10n_in_journal_id = journal.id diff --git a/addons/l10n_in_purchase/views/purchase_order_views.xml b/addons/l10n_in_purchase/views/purchase_order_views.xml new file mode 100644 index 00000000000..f60d9dae8f9 --- /dev/null +++ b/addons/l10n_in_purchase/views/purchase_order_views.xml @@ -0,0 +1,13 @@ + + + + purchase.order.form.inherit.l10n.in.purchase + purchase.order + + + + + + + + diff --git a/addons/l10n_in_purchase_stock/__init__.py b/addons/l10n_in_purchase_stock/__init__.py new file mode 100644 index 00000000000..dc5e6b693d1 --- /dev/null +++ b/addons/l10n_in_purchase_stock/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import models diff --git a/addons/l10n_in_purchase_stock/__manifest__.py b/addons/l10n_in_purchase_stock/__manifest__.py new file mode 100644 index 00000000000..d79c30f52eb --- /dev/null +++ b/addons/l10n_in_purchase_stock/__manifest__.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +{ + 'name': "India Purchase and Warehouse Management", + + 'summary': """ + Define default purchase journal on the warehouse""", + + 'description': """ + Define default purchase journal on the warehouse, + help you to choose correct purchase journal on the purchase order when + you change the picking operation. + useful when you setup the multiple GSTIN units. + """, + + 'author': "Odoo", + 'website': "https://www.odoo.com", + 'category': 'Accounting/Accounting', + 'version': '1.0', + + 'depends': ['l10n_in_purchase', 'l10n_in_stock'], + + 'data': [ + 'views/stock_warehouse_views.xml', + ], + 'auto_install': True +} diff --git a/addons/l10n_in_purchase_stock/models/__init__.py b/addons/l10n_in_purchase_stock/models/__init__.py new file mode 100644 index 00000000000..b1a8586e9e1 --- /dev/null +++ b/addons/l10n_in_purchase_stock/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import purchase_order +from . import stock_warehouse diff --git a/addons/l10n_in_purchase_stock/models/purchase_order.py b/addons/l10n_in_purchase_stock/models/purchase_order.py new file mode 100644 index 00000000000..3278769c2e5 --- /dev/null +++ b/addons/l10n_in_purchase_stock/models/purchase_order.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, fields, api + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + @api.onchange('company_id', 'picking_type_id') + def l10n_in_onchange_company_id(self): + if self.picking_type_id.warehouse_id and self.picking_type_id.warehouse_id.l10n_in_purchase_journal_id: + self.l10n_in_journal_id = self.picking_type_id.warehouse_id.l10n_in_purchase_journal_id.id + else: + super().l10n_in_onchange_company_id() diff --git a/addons/l10n_in_purchase_stock/models/stock_warehouse.py b/addons/l10n_in_purchase_stock/models/stock_warehouse.py new file mode 100644 index 00000000000..5fa743e3f45 --- /dev/null +++ b/addons/l10n_in_purchase_stock/models/stock_warehouse.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, fields, api + + +class Stock(models.Model): + _inherit = 'stock.warehouse' + + l10n_in_purchase_journal_id = fields.Many2one('account.journal', string="Purchase Journal") diff --git a/addons/l10n_in_purchase_stock/views/stock_warehouse_views.xml b/addons/l10n_in_purchase_stock/views/stock_warehouse_views.xml new file mode 100644 index 00000000000..69df7c9b1d9 --- /dev/null +++ b/addons/l10n_in_purchase_stock/views/stock_warehouse_views.xml @@ -0,0 +1,13 @@ + + + + stock.warehouse.form.inherit.l10n.in.stock + stock.warehouse + + + + + + + + diff --git a/addons/l10n_in_sale/__init__.py b/addons/l10n_in_sale/__init__.py index 2609681a938..de3c67453a7 100644 --- a/addons/l10n_in_sale/__init__.py +++ b/addons/l10n_in_sale/__init__.py @@ -3,3 +3,4 @@ from . import models from . import report +from . import wizard diff --git a/addons/l10n_in_sale/models/sale_order.py b/addons/l10n_in_sale/models/sale_order.py index 0dd61a784a3..7062c0685af 100644 --- a/addons/l10n_in_sale/models/sale_order.py +++ b/addons/l10n_in_sale/models/sale_order.py @@ -9,8 +9,19 @@ class SaleOrder(models.Model): l10n_in_reseller_partner_id = fields.Many2one('res.partner', string='Reseller', domain="[('vat', '!=', False), '|', ('company_id', '=', False), ('company_id', '=', company_id)]", states={'posted': [('readonly', True)]}) + l10n_in_journal_id = fields.Many2one('account.journal', string="Journal", states={'posted': [('readonly', True)]}) def _prepare_invoice(self): invoice_vals = super(SaleOrder, self)._prepare_invoice() invoice_vals['l10n_in_reseller_partner_id'] = self.l10n_in_reseller_partner_id.id + if self.l10n_in_journal_id: + invoice_vals['journal_id'] = self.l10n_in_journal_id.id return invoice_vals + + @api.onchange('company_id') + def l10n_in_onchange_company_id(self): + domain = [('company_id', '=', self.company_id.id), ('type', '=', 'sale')] + + journal = self.env['account.journal'].search(domain, limit=1) + if journal: + self.l10n_in_journal_id = journal.id diff --git a/addons/l10n_in_sale/views/sale_views.xml b/addons/l10n_in_sale/views/sale_views.xml index 868b744f49c..af9ad82b80e 100644 --- a/addons/l10n_in_sale/views/sale_views.xml +++ b/addons/l10n_in_sale/views/sale_views.xml @@ -8,6 +8,9 @@ + + + diff --git a/addons/l10n_in_sale/wizard/__init__.py b/addons/l10n_in_sale/wizard/__init__.py new file mode 100644 index 00000000000..46b1c608a3d --- /dev/null +++ b/addons/l10n_in_sale/wizard/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import sale_make_invoice_advance diff --git a/addons/l10n_in_sale/wizard/sale_make_invoice_advance.py b/addons/l10n_in_sale/wizard/sale_make_invoice_advance.py new file mode 100644 index 00000000000..880f07d2537 --- /dev/null +++ b/addons/l10n_in_sale/wizard/sale_make_invoice_advance.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models + + +class SaleAdvancePaymentInv(models.TransientModel): + _inherit = "sale.advance.payment.inv" + + def _create_invoice(self, order, so_line, amount): + invoice = super()._create_invoice(order, so_line, amount) + if order.l10n_in_journal_id: + invoice.journal_id = order.l10n_in_journal_id + return invoice diff --git a/addons/l10n_in_sale_stock/__init__.py b/addons/l10n_in_sale_stock/__init__.py new file mode 100644 index 00000000000..dc5e6b693d1 --- /dev/null +++ b/addons/l10n_in_sale_stock/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import models diff --git a/addons/l10n_in_sale_stock/__manifest__.py b/addons/l10n_in_sale_stock/__manifest__.py new file mode 100644 index 00000000000..1e9e19981af --- /dev/null +++ b/addons/l10n_in_sale_stock/__manifest__.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +{ + 'name': "India Sales and Warehouse Management", + + 'summary': """ + Define default sales journal on the warehouse""", + + 'description': """ + Define default sales journal on the warehouse, + help you to choose correct sales journal on the sales order when + you change the warehouse. + useful when you setup the multiple GSTIN units. + """, + + 'author': "Odoo", + 'website': "https://www.odoo.com", + 'category': 'Accounting/Accounting', + 'version': '0.1', + + 'depends': ['l10n_in_sale', 'l10n_in_stock'], + + 'data': [ + 'views/stock_warehouse_views.xml', + ], + 'auto_install': True +} diff --git a/addons/l10n_in_sale_stock/models/__init__.py b/addons/l10n_in_sale_stock/models/__init__.py new file mode 100644 index 00000000000..fcfd6a142db --- /dev/null +++ b/addons/l10n_in_sale_stock/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import sale_order +from . import stock_warehouse diff --git a/addons/l10n_in_sale_stock/models/sale_order.py b/addons/l10n_in_sale_stock/models/sale_order.py new file mode 100644 index 00000000000..02b46faaf8a --- /dev/null +++ b/addons/l10n_in_sale_stock/models/sale_order.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, fields, api + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + @api.onchange('company_id', 'warehouse_id') + def l10n_in_onchange_company_id(self): + if self.warehouse_id.l10n_in_sale_journal_id: + self.l10n_in_journal_id = self.warehouse_id.l10n_in_sale_journal_id.id + else: + super().l10n_in_onchange_company_id() diff --git a/addons/l10n_in_sale_stock/models/stock_warehouse.py b/addons/l10n_in_sale_stock/models/stock_warehouse.py new file mode 100644 index 00000000000..190e0b2750d --- /dev/null +++ b/addons/l10n_in_sale_stock/models/stock_warehouse.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, fields, api + + +class Stock(models.Model): + _inherit = 'stock.warehouse' + + l10n_in_sale_journal_id = fields.Many2one('account.journal', string="Sale Journal") diff --git a/addons/l10n_in_sale_stock/views/stock_warehouse_views.xml b/addons/l10n_in_sale_stock/views/stock_warehouse_views.xml new file mode 100644 index 00000000000..0329dc01d2d --- /dev/null +++ b/addons/l10n_in_sale_stock/views/stock_warehouse_views.xml @@ -0,0 +1,13 @@ + + + + stock.warehouse.form.inherit.l10n.in.stock + stock.warehouse + + + + + + + +