From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/l10n_in_purchase/__init__.py | 4 ++ addons/l10n_in_purchase/__manifest__.py | 21 +++++++++++ addons/l10n_in_purchase/models/__init__.py | 5 +++ addons/l10n_in_purchase/models/account_move.py | 18 +++++++++ addons/l10n_in_purchase/models/purchase_order.py | 43 ++++++++++++++++++++++ .../views/purchase_order_views.xml | 17 +++++++++ .../views/report_purchase_order.xml | 32 ++++++++++++++++ 7 files changed, 140 insertions(+) create mode 100644 addons/l10n_in_purchase/__init__.py create mode 100644 addons/l10n_in_purchase/__manifest__.py 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/views/report_purchase_order.xml (limited to 'addons/l10n_in_purchase') diff --git a/addons/l10n_in_purchase/__init__.py b/addons/l10n_in_purchase/__init__.py new file mode 100644 index 00000000..dc5e6b69 --- /dev/null +++ b/addons/l10n_in_purchase/__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/__manifest__.py b/addons/l10n_in_purchase/__manifest__.py new file mode 100644 index 00000000..bcecef57 --- /dev/null +++ b/addons/l10n_in_purchase/__manifest__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +{ + 'name': 'Indian - Purchase Report(GST)', + 'version': '1.0', + 'description': """GST Purchase Report""", + 'category': 'Accounting/Localizations/Purchase', + 'depends': [ + 'l10n_in', + 'purchase', + ], + 'data': [ + 'views/report_purchase_order.xml', + 'views/purchase_order_views.xml', + ], + 'installable': True, + 'application': False, + 'auto_install': True, + 'license': 'LGPL-3', +} diff --git a/addons/l10n_in_purchase/models/__init__.py b/addons/l10n_in_purchase/models/__init__.py new file mode 100644 index 00000000..476326ad --- /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 00000000..c753c2cc --- /dev/null +++ b/addons/l10n_in_purchase/models/account_move.py @@ -0,0 +1,18 @@ +# -*- 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): + purchase_order_id = self.purchase_vendor_bill_id.purchase_order_id or self.purchase_id + if purchase_order_id and self.l10n_in_company_country_code == 'IN': + 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 + self.l10n_in_gst_treatment = purchase_order_id.l10n_in_gst_treatment + 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 00000000..a7d0d4ac --- /dev/null +++ b/addons/l10n_in_purchase/models/purchase_order.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models +from odoo.addons.purchase.models.purchase import PurchaseOrder as Purchase + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + l10n_in_journal_id = fields.Many2one('account.journal', string="Journal", \ + states=Purchase.READONLY_STATES, domain="[('type', '=', 'purchase')]") + l10n_in_gst_treatment = fields.Selection([ + ('regular', 'Registered Business - Regular'), + ('composition', 'Registered Business - Composition'), + ('unregistered', 'Unregistered Business'), + ('consumer', 'Consumer'), + ('overseas', 'Overseas'), + ('special_economic_zone', 'Special Economic Zone'), + ('deemed_export', 'Deemed Export') + ], string="GST Treatment", states=Purchase.READONLY_STATES, compute="_compute_l10n_in_gst_treatment", store=True) + l10n_in_company_country_code = fields.Char(related='company_id.country_id.code', string="Country code") + + @api.onchange('company_id') + def l10n_in_onchange_company_id(self): + if self.l10n_in_company_country_code == 'IN': + 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 + + @api.depends('partner_id') + def _compute_l10n_in_gst_treatment(self): + for order in self: + # set default value as False so CacheMiss error never occurs for this field. + order.l10n_in_gst_treatment = False + if order.l10n_in_company_country_code == 'IN': + l10n_in_gst_treatment = order.partner_id.l10n_in_gst_treatment + if not l10n_in_gst_treatment and order.partner_id.country_id and order.partner_id.country_id.code != 'IN': + l10n_in_gst_treatment = 'overseas' + if not l10n_in_gst_treatment: + l10n_in_gst_treatment = order.partner_id.vat and 'regular' or 'consumer' + order.l10n_in_gst_treatment = l10n_in_gst_treatment 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 00000000..4200706e --- /dev/null +++ b/addons/l10n_in_purchase/views/purchase_order_views.xml @@ -0,0 +1,17 @@ + + + + purchase.order.form.inherit.l10n.in.purchase + purchase.order + + + + + + + + + + + + diff --git a/addons/l10n_in_purchase/views/report_purchase_order.xml b/addons/l10n_in_purchase/views/report_purchase_order.xml new file mode 100644 index 00000000..f2ffc084 --- /dev/null +++ b/addons/l10n_in_purchase/views/report_purchase_order.xml @@ -0,0 +1,32 @@ + + + + + + + + -- cgit v1.2.3