|
@ -1,49 +1,49 @@ |
|
|
# -*- coding: utf-8 -*- |
|
|
# -*- coding: utf-8 -*- |
|
|
############################################################################# |
|
|
############################################################################### |
|
|
# |
|
|
# |
|
|
# Cybrosys Technologies Pvt. Ltd. |
|
|
# Cybrosys Technologies Pvt. Ltd. |
|
|
# |
|
|
# |
|
|
# Copyright (C) 2019-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). |
|
|
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|
|
# Author: Vishnu KP @ Cybrosys, (odoo@cybrosys.com) |
|
|
# Author: Vishnu KP S (odoo@cybrosys.com) |
|
|
# |
|
|
# |
|
|
# You can modify it under the terms of the GNU AFFERO |
|
|
# This program is under the terms of the Odoo Proprietary License v1.0 (OPL-1) |
|
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|
|
# It is forbidden to publish, distribute, sublicense, or sell copies of the |
|
|
|
|
|
# Software or modified copies of the Software. |
|
|
# |
|
|
# |
|
|
# This program is distributed in the hope that it will be useful, |
|
|
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL |
|
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|
|
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,DAMAGES OR OTHER |
|
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,ARISING |
|
|
|
|
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|
|
|
|
|
# DEALINGS IN THE SOFTWARE. |
|
|
# |
|
|
# |
|
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|
|
############################################################################### |
|
|
# (AGPL v3) along with this program. |
|
|
|
|
|
# If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
|
# |
|
|
|
|
|
############################################################################# |
|
|
|
|
|
from odoo import fields, models, _ |
|
|
from odoo import fields, models, _ |
|
|
from odoo.exceptions import UserError |
|
|
from odoo.exceptions import UserError |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MobileInvoice(models.Model): |
|
|
class MobileInvoice(models.Model): |
|
|
|
|
|
|
|
|
_name = 'mobile.invoice' |
|
|
_name = 'mobile.invoice' |
|
|
|
|
|
|
|
|
advance_payment_method = fields.Selection([('advance', 'Advance'), ('full_amount', 'Full amount')], |
|
|
advance_payment_method = fields.Selection( |
|
|
string='Invoice method', default='advance') |
|
|
[('advance', 'Advance'), ('full_amount', 'Full amount')], |
|
|
amount = fields.Integer(string='Amount') |
|
|
string='Invoice method', default='advance') |
|
|
number = fields.Char(string='Service Id') |
|
|
amount = fields.Integer(string='Amount', help="Payment Amount") |
|
|
|
|
|
number = fields.Char(string='Service Id', help="Payment service id'") |
|
|
|
|
|
|
|
|
def action_invoice_create(self): |
|
|
def action_invoice_create(self): |
|
|
"""Creating invoice""" |
|
|
"""Creating invoice""" |
|
|
active_id = self._context.get('active_id') |
|
|
active_id = self._context.get('active_id') |
|
|
service_id = self.env['mobile.service'].search([('id', '=', active_id)]) |
|
|
service_id = self.env['mobile.service'].search([('id', '=', active_id)]) |
|
|
if not service_id.env['product.product'].search([("name", "=", "Mobile Service Advance")]): |
|
|
if not service_id.env['product.product'].search( |
|
|
|
|
|
[("name", "=", "Mobile Service Advance")]): |
|
|
vals = self._prepare_advance_product() |
|
|
vals = self._prepare_advance_product() |
|
|
self.env['product.product'].create(vals) |
|
|
self.env['product.product'].create(vals) |
|
|
|
|
|
if not service_id.env['product.product'].search( |
|
|
if not service_id.env['product.product'].search([("name", "=", "Mobile Service Charge")]): |
|
|
[("name", "=", "Mobile Service Charge")]): |
|
|
vals1 = self._prepare_service_product() |
|
|
vals1 = self._prepare_service_product() |
|
|
self.env['product.product'].create(vals1) |
|
|
self.env['product.product'].create(vals1) |
|
|
|
|
|
|
|
|
service_id.first_invoice_created = True |
|
|
service_id.first_invoice_created = True |
|
|
inv_obj = self.env['account.move'] |
|
|
inv_obj = self.env['account.move'] |
|
|
supplier = service_id.person_name |
|
|
supplier = service_id.person_name |
|
@ -60,17 +60,19 @@ class MobileInvoice(models.Model): |
|
|
service_id.first_payment_inv = inv_id.id |
|
|
service_id.first_payment_inv = inv_id.id |
|
|
self.number = service_id.name |
|
|
self.number = service_id.name |
|
|
if self.advance_payment_method != 'advance': |
|
|
if self.advance_payment_method != 'advance': |
|
|
product_id = service_id.env['product.product'].search([("name", "=", "Mobile Service Charge")]) |
|
|
product_id = service_id.env['product.product'].search( |
|
|
|
|
|
[("name", "=", "Mobile Service Charge")]) |
|
|
else: |
|
|
else: |
|
|
product_id = service_id.env['product.product'].search([("name", "=", "Mobile Service Advance")]) |
|
|
product_id = service_id.env['product.product'].search( |
|
|
|
|
|
[("name", "=", "Mobile Service Advance")]) |
|
|
if product_id.property_account_income_id.id: |
|
|
if product_id.property_account_income_id.id: |
|
|
income_account = product_id.property_account_income_id.id |
|
|
income_account = product_id.property_account_income_id.id |
|
|
elif product_id.categ_id.property_account_income_categ_id.id: |
|
|
elif product_id.categ_id.property_account_income_categ_id.id: |
|
|
income_account = product_id.categ_id.property_account_income_categ_id.id |
|
|
income_account = product_id.categ_id.property_account_income_categ_id.id |
|
|
else: |
|
|
else: |
|
|
raise UserError('Please define income account for this product: "%s" (id:%d).' % |
|
|
raise UserError( |
|
|
(product_id.name, product_id.id)) |
|
|
_(f'Please define income account for this ' |
|
|
|
|
|
f'product: "{product_id.name}" (id:{product_id.id}).')) |
|
|
flag = 0 |
|
|
flag = 0 |
|
|
if self.amount: |
|
|
if self.amount: |
|
|
flag = 1 |
|
|
flag = 1 |
|
@ -88,11 +90,13 @@ class MobileInvoice(models.Model): |
|
|
'invoice_line_ids': inv_line_data}) |
|
|
'invoice_line_ids': inv_line_data}) |
|
|
inv_id._compute_journal_id() |
|
|
inv_id._compute_journal_id() |
|
|
|
|
|
|
|
|
sale_order_product = self.env['product.order.line'].search([('product_order_id', '=', service_id.name)]) |
|
|
sale_order_product = self.env['product.order.line'].search( |
|
|
|
|
|
[('product_order_id', '=', service_id.name)]) |
|
|
for line_data in sale_order_product: |
|
|
for line_data in sale_order_product: |
|
|
qty = line_data.product_uom_qty - line_data.qty_invoiced |
|
|
qty = line_data.product_uom_qty - line_data.qty_invoiced |
|
|
if line_data.product_uom_qty < line_data.qty_invoiced: |
|
|
if line_data.product_uom_qty < line_data.qty_invoiced: |
|
|
raise UserError(_('Used quantity is less than invoiced quantity')) |
|
|
raise UserError( |
|
|
|
|
|
_('Used quantity is less than invoiced quantity')) |
|
|
uom_id = line_data.product_id.product_tmpl_id.uom_id |
|
|
uom_id = line_data.product_id.product_tmpl_id.uom_id |
|
|
if qty > 0: |
|
|
if qty > 0: |
|
|
flag = 1 |
|
|
flag = 1 |
|
@ -123,14 +127,15 @@ class MobileInvoice(models.Model): |
|
|
'name': action.name, |
|
|
'name': action.name, |
|
|
'help': action.help, |
|
|
'help': action.help, |
|
|
'type': 'ir.actions.act_window', |
|
|
'type': 'ir.actions.act_window', |
|
|
'views': [[list_view_id, 'tree'], [form_view_id, 'form'], [False, 'graph'], [False, 'kanban'], |
|
|
'views': [[list_view_id, 'tree'], [form_view_id, 'form'], |
|
|
|
|
|
[False, 'graph'], [False, 'kanban'], |
|
|
[False, 'calendar'], [False, 'pivot']], |
|
|
[False, 'calendar'], [False, 'pivot']], |
|
|
'target': action.target, |
|
|
'target': action.target, |
|
|
'context': action.context, |
|
|
'context': action.context, |
|
|
'res_model': 'account.move', |
|
|
'res_model': 'account.move', |
|
|
} |
|
|
} |
|
|
if len(inv_id) > 1: |
|
|
if len(inv_id) > 1: |
|
|
result['domain'] = "[('id','in',%s)]" % inv_id.ids |
|
|
result['domain'] = f"[('id','in',{inv_id.ids})]" |
|
|
elif len(inv_id) == 1: |
|
|
elif len(inv_id) == 1: |
|
|
result['views'] = [(form_view_id, 'form')] |
|
|
result['views'] = [(form_view_id, 'form')] |
|
|
result['res_id'] = inv_id.ids[0] |
|
|
result['res_id'] = inv_id.ids[0] |
|
|