diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-08-10 11:32:18 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-08-10 11:32:18 +0700 |
| commit | 4fd0d7f15ee2d7958c6d9c60faf03d1e9915eaef (patch) | |
| tree | b6ab45c654dfc9b4aa08b878b823b0010331d63f | |
| parent | 7b4f47e43d6485bb7822f1eb21497e68ab782ab1 (diff) | |
| parent | 81c87b71d6cb7caad7230b9cca8545155d917214 (diff) | |
Merge branch 'production' of https://bitbucket.org/altafixco/indoteknik-addons into production
| -rw-r--r-- | indoteknik_api/controllers/api_v1/sale_order.py | 14 | ||||
| -rwxr-xr-x | indoteknik_custom/__manifest__.py | 3 | ||||
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 6 | ||||
| -rw-r--r-- | indoteknik_custom/models/account_financial_report.py | 17 | ||||
| -rw-r--r-- | indoteknik_custom/models/account_general_ledger.py | 133 | ||||
| -rw-r--r-- | indoteknik_custom/models/account_report_financial.py | 158 | ||||
| -rw-r--r-- | indoteknik_custom/models/account_report_general_ledger.py | 226 | ||||
| -rw-r--r-- | indoteknik_custom/models/airway_bill_manifest.py | 11 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_order.py | 15 | ||||
| -rwxr-xr-x | indoteknik_custom/models/purchase_order_line.py | 15 | ||||
| -rw-r--r-- | indoteknik_custom/views/account_financial_report_view.xml | 51 | ||||
| -rw-r--r-- | indoteknik_custom/views/account_report_general_ledger_view.xml | 37 | ||||
| -rw-r--r-- | indoteknik_custom/views/mail_template_po.xml | 86 | ||||
| -rwxr-xr-x | indoteknik_custom/views/purchase_order.xml | 3 | ||||
| -rw-r--r-- | indoteknik_custom/views/raja_ongkir.xml | 242 |
15 files changed, 890 insertions, 127 deletions
diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index 1ad1ff51..ecc6c771 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -1,5 +1,6 @@ from .. import controller from odoo import http +from datetime import datetime, timedelta from odoo.http import request import json @@ -389,6 +390,17 @@ class SaleOrder(controller.Controller): data = airway_bill.decode_response() delivery_order = airway_bill.do_id result = data['rajaongkir']['result'] + + manifests_data = [] + for manifest in airway_bill.manifest_ids: + manifest_data = { + 'code': manifest.code, + 'description': manifest.description, + 'datetime': datetime.strftime(manifest.datetime, '%Y-%m-%d %H:%M:%S'), + 'city': manifest.city, + } + manifests_data.append(manifest_data) + airways.append({ 'delivery_order': { 'name': delivery_order.name, @@ -399,7 +411,7 @@ class SaleOrder(controller.Controller): 'delivered': result['delivered'], 'waybill_number': result['summary']['waybill_number'], 'delivery_status': result['delivery_status'], - 'manifests': result['manifest'] + 'manifests': manifests_data }) response = {'airways': airways} diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index b7aadbdf..18031c25 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -84,9 +84,12 @@ 'views/product_sla.xml', 'views/voucher.xml', 'views/bill_receipt.xml', + 'views/account_financial_report_view.xml', + 'views/account_report_general_ledger_view.xml', 'views/account_move_multi_update.xml', 'views/airway_bill.xml', 'views/product_attribute_value.xml', + 'views/mail_template_po.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 54e24563..843beeae 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -74,4 +74,8 @@ from . import airway_bill_manifest from . import account_move_due_extension from . import voucher from . import bill_receipt -from . import account_move_multi_update
\ No newline at end of file +from . import account_move_multi_update +from . import account_financial_report +from . import account_general_ledger +from . import account_report_financial +from . import account_report_general_ledger diff --git a/indoteknik_custom/models/account_financial_report.py b/indoteknik_custom/models/account_financial_report.py new file mode 100644 index 00000000..1bf6816a --- /dev/null +++ b/indoteknik_custom/models/account_financial_report.py @@ -0,0 +1,17 @@ +from datetime import datetime +import json +import datetime +import io +from odoo import api, fields, models, _ +from odoo.tools import date_utils +try: + from odoo.tools.misc import xlsxwriter +except ImportError: + import xlsxwriter + + +class AccountingReport(models.TransientModel): + _inherit = "accounting.report.xlsx" + + +
\ No newline at end of file diff --git a/indoteknik_custom/models/account_general_ledger.py b/indoteknik_custom/models/account_general_ledger.py new file mode 100644 index 00000000..e80696a4 --- /dev/null +++ b/indoteknik_custom/models/account_general_ledger.py @@ -0,0 +1,133 @@ +import time +from odoo import api, models, _ +from odoo.exceptions import UserError + +class ReportGeneralLedger(models.AbstractModel): + _name = 'report.account.report_generalledger' + + def _get_account_move_entry_custom(self, accounts, init_balance, sortby, display_account): + """ + :param: + accounts: the recordset of accounts + init_balance: boolean value of initial_balance + sortby: sorting by date or partner and journal + display_account: type of account(receivable, payable and both) + + Returns a dictionary of accounts with following key and value { + 'code': account code, + 'name': account name, + 'debit': sum of total debit amount, + 'credit': sum of total credit amount, + 'balance': total balance, + 'amount_currency': sum of amount_currency, + 'move_lines': list of move line + } + """ + cr = self.env.cr + MoveLine = self.env['account.move.line'] + move_lines = {x: [] for x in accounts.ids} + + # Prepare initial sql query and Get the initial move lines + if init_balance: + init_tables, init_where_clause, init_where_params = MoveLine.with_context(date_from=self.env.context.get('date_from'), date_to=False, initial_bal=True)._query_get() + init_wheres = [""] + if init_where_clause.strip(): + init_wheres.append(init_where_clause.strip()) + init_filters = " AND ".join(init_wheres) + filters = init_filters.replace('account_move_line__move_id', 'm').replace('account_move_line', 'l') + sql = ("""SELECT 0 AS lid, l.account_id AS account_id, '' AS ldate, '' AS lcode, 0.0 AS amount_currency, '' AS lref, 'Initial Balance' AS lname, COALESCE(SUM(l.debit),0.0) AS debit, COALESCE(SUM(l.credit),0.0) AS credit, COALESCE(SUM(l.debit),0) - COALESCE(SUM(l.credit), 0) as balance, '' AS lpartner_id,\ + '' AS move_name, '' AS mmove_id, '' AS currency_code,\ + NULL AS currency_id,\ + '' AS invoice_id, '' AS invoice_type, '' AS invoice_number,\ + '' AS partner_name\ + FROM account_move_line l\ + LEFT JOIN account_move m ON (l.move_id=m.id)\ + LEFT JOIN res_currency c ON (l.currency_id=c.id)\ + LEFT JOIN res_partner p ON (l.partner_id=p.id)\ + LEFT JOIN account_move i ON (m.id =i.id)\ + JOIN account_journal j ON (l.journal_id=j.id)\ + WHERE l.account_id IN %s""" + filters + ' GROUP BY l.account_id') + params = (tuple(accounts.ids),) + tuple(init_where_params) + cr.execute(sql, params) + for row in cr.dictfetchall(): + move_lines[row.pop('account_id')].append(row) + + sql_sort = 'l.date, l.move_id' + if sortby == 'sort_journal_partner': + sql_sort = 'j.code, p.name, l.move_id' + + # Prepare sql query base on selected parameters from wizard + tables, where_clause, where_params = MoveLine._query_get() + wheres = [""] + if where_clause.strip(): + wheres.append(where_clause.strip()) + filters = " AND ".join(wheres) + filters = filters.replace('account_move_line__move_id', 'm').replace('account_move_line', 'l') + + # Get move lines base on sql query and Calculate the total balance of move lines + sql = ('''SELECT l.id AS lid, l.account_id AS account_id, l.date AS ldate, j.code AS lcode, l.currency_id, l.amount_currency, l.ref AS lref, l.name AS lname, COALESCE(l.debit,0) AS debit, COALESCE(l.credit,0) AS credit, COALESCE(SUM(l.debit),0) - COALESCE(SUM(l.credit), 0) AS balance,\ + m.name AS move_name, c.symbol AS currency_code, p.name AS partner_name\ + FROM account_move_line l\ + JOIN account_move m ON (l.move_id=m.id)\ + LEFT JOIN res_currency c ON (l.currency_id=c.id)\ + LEFT JOIN res_partner p ON (l.partner_id=p.id)\ + JOIN account_journal j ON (l.journal_id=j.id)\ + JOIN account_account acc ON (l.account_id = acc.id) \ + WHERE l.account_id IN %s ''' + filters + ''' GROUP BY l.id, l.account_id, l.date, j.code, l.currency_id, l.amount_currency, l.ref, l.name, m.name, c.symbol, p.name ORDER BY ''' + sql_sort) + params = (tuple(accounts.ids),) + tuple(where_params) + cr.execute(sql, params) + + for row in cr.dictfetchall(): + balance = 0 + for line in move_lines.get(row['account_id']): + balance += line['debit'] - line['credit'] + row['balance'] += balance + move_lines[row.pop('account_id')].append(row) + + # Calculate the debit, credit and balance for Accounts + account_res = [] + for account in accounts: + currency = account.currency_id and account.currency_id or account.company_id.currency_id + res = dict((fn, 0.0) for fn in ['credit', 'debit', 'balance', 'balance_month']) + res['code'] = account.code + res['name'] = account.name + res['company_id'] = account.company_id.id + res['move_lines'] = move_lines[account.id] + for line in res.get('move_lines'): + res['debit'] += line['debit'] + res['credit'] += line['credit'] + res['balance'] = line['balance'] + if display_account == 'all': + account_res.append(res) + if display_account == 'movement' and res.get('move_lines'): + account_res.append(res) + if display_account == 'not_zero' and not currency.is_zero(res['balance']): + account_res.append(res) + return account_res + + @api.model + def _get_report_values(self, docids, data=None): + if not data.get('form') or not self.env.context.get('active_model'): + raise UserError(_("Form content is missing, this report cannot be printed.")) + + model = self.env.context.get('active_model') + docs = self.env[model].browse(self.env.context.get('active_ids', [])) + + init_balance = data['form'].get('initial_balance', True) + sortby = data['form'].get('sortby', 'sort_date') + display_account = data['form']['display_account'] + codes = [] + if data['form'].get('journal_ids', False): + codes = [journal.code for journal in self.env['account.journal'].search([('id', 'in', data['form']['journal_ids'])])] + + accounts = docs if model == 'account.account' else self.env['account.account'].search([]) + accounts_res = self.with_context(data['form'].get('used_context',{}))._get_account_move_entry_custom(accounts, init_balance, sortby, display_account) + return { + 'doc_ids': docids, + 'doc_model': model, + 'data': data['form'], + 'docs': docs, + 'time': time, + 'Accounts': accounts_res, + 'print_journal': codes, + } diff --git a/indoteknik_custom/models/account_report_financial.py b/indoteknik_custom/models/account_report_financial.py new file mode 100644 index 00000000..c11fa25b --- /dev/null +++ b/indoteknik_custom/models/account_report_financial.py @@ -0,0 +1,158 @@ +import time +from odoo import api, models, _ +from odoo.exceptions import UserError + + +class ReportFinancial(models.AbstractModel): + _inherit = 'report.account.report_financial' + + def _compute_account_balance(self, accounts): + """ compute the balance, debit and credit for the provided accounts """ + mapping = { + 'balance': "COALESCE(SUM(debit),0) - COALESCE(SUM(credit), 0) as balance", + 'debit': "COALESCE(SUM(debit), 0) as debit", + 'credit': "COALESCE(SUM(credit), 0) as credit", + } + + res = {} + for account in accounts: + res[account.id] = dict.fromkeys(mapping, 0.0) + if accounts: + tables, where_clause, where_params = self.env['account.move.line']._query_get() + tables = tables.replace('"', '') if tables else "account_move_line" + wheres = [""] + if where_clause.strip(): + wheres.append(where_clause.strip()) + filters = " AND ".join(wheres) + request = "SELECT account_id as id, " + ', '.join(mapping.values()) + \ + " FROM " + tables + \ + " WHERE account_id IN %s " \ + + filters + \ + " GROUP BY account_id" + params = (tuple(accounts._ids),) + tuple(where_params) + self.env.cr.execute(request, params) + for row in self.env.cr.dictfetchall(): + res[row['id']] = row + return res + + def _compute_report_balance(self, reports): + '''returns a dictionary with key=the ID of a record and value=the credit, debit and balance amount + computed for this record. If the record is of type : + 'accounts' : it's the sum of the linked accounts + 'account_type' : it's the sum of leaf accoutns with such an account_type + 'account_report' : it's the amount of the related report + 'sum' : it's the sum of the children of this record (aka a 'view' record)''' + res = {} + fields = ['credit', 'debit', 'balance'] + for report in reports: + if report.id in res: + continue + res[report.id] = dict((fn, 0.0) for fn in fields) + if report.type == 'accounts': + # it's the sum of the linked accounts + res[report.id]['account'] = self._compute_account_balance(report.account_ids) + for value in res[report.id]['account'].values(): + for field in fields: + res[report.id][field] += value.get(field) + elif report.type == 'account_type': + # it's the sum the leaf accounts with such an account type + accounts = self.env['account.account'].search([('user_type_id', 'in', report.account_type_ids.ids)]) + res[report.id]['account'] = self._compute_account_balance(accounts) + for value in res[report.id]['account'].values(): + for field in fields: + res[report.id][field] += value.get(field) + elif report.type == 'account_report' and report.account_report_id: + # it's the amount of the linked report + res2 = self._compute_report_balance(report.account_report_id) + for key, value in res2.items(): + for field in fields: + res[report.id][field] += value[field] + elif report.type == 'sum': + # it's the sum of the children of this account.report + res2 = self._compute_report_balance(report.children_ids) + for key, value in res2.items(): + for field in fields: + res[report.id][field] += value[field] + return res + + def get_account_lines(self, data): + lines = [] + account_report = self.env['account.financial.report'].search([('id', '=', data['account_report_id'][0])]) + child_reports = account_report._get_children_by_order() + res = self.with_context(data.get('used_context'))._compute_report_balance(child_reports) + if data['enable_filter']: + comparison_res = self.with_context(data.get('comparison_context'))._compute_report_balance(child_reports) + for report_id, value in comparison_res.items(): + res[report_id]['comp_bal'] = value['balance'] + report_acc = res[report_id].get('account') + if report_acc: + for account_id, val in comparison_res[report_id].get('account').items(): + report_acc[account_id]['comp_bal'] = val['balance'] + + for report in child_reports: + vals = { + 'name': report.name, + 'balance': res[report.id]['balance'] * int(report.sign), + 'type': 'report', + 'level': bool(report.style_overwrite) and report.level, + 'account_type': report.type or False, #used to underline the financial report balances + } + if data['debit_credit']: + vals['debit'] = res[report.id]['debit'] + vals['credit'] = res[report.id]['credit'] + + if data['enable_filter']: + vals['balance_cmp'] = res[report.id]['comp_bal'] * int(report.sign) + + lines.append(vals) + if report.display_detail == 'no_detail': + #the rest of the loop is used to display the details of the financial report, so it's not needed here. + continue + + if res[report.id].get('account'): + sub_lines = [] + for account_id, value in res[report.id]['account'].items(): + #if there are accounts to display, we add them to the lines with a level equals to their level in + #the COA + 1 (to avoid having them with a too low level that would conflicts with the level of data + #financial reports for Assets, liabilities...) + flag = False + account = self.env['account.account'].browse(account_id) + vals = { + 'name': account.code + ' ' + account.name, + 'balance': value['balance'] * int(report.sign) or 0.0, + 'type': 'account', + 'level': report.display_detail == 'detail_with_hierarchy' and 4, + 'account_type': account.internal_type, + } + if data['debit_credit']: + vals['debit'] = value['debit'] + vals['credit'] = value['credit'] + if not account.company_id.currency_id.is_zero(vals['debit']) or not account.company_id.currency_id.is_zero(vals['credit']): + flag = True + if not account.company_id.currency_id.is_zero(vals['balance']): + flag = True + if data['enable_filter']: + vals['balance_cmp'] = value['comp_bal'] * int(report.sign) + if not account.company_id.currency_id.is_zero(vals['balance_cmp']): + flag = True + if flag: + sub_lines.append(vals) + lines += sorted(sub_lines, key=lambda sub_line: sub_line['name']) + return lines + + @api.model + def get_report_values(self, docids, data=None): + if not data.get('form') or not self.env.context.get('active_model') or not self.env.context.get('active_id'): + raise UserError(_("Form content is missing, this report cannot be printed.")) + + self.model = self.env.context.get('active_model') + docs = self.env[self.model].browse(self.env.context.get('active_id')) + report_lines = self.get_account_lines(data.get('form')) + return { + 'doc_ids': self.ids, + 'doc_model': self.model, + 'data': data['form'], + 'docs': docs, + 'time': time, + 'get_account_lines': report_lines, + }
\ No newline at end of file diff --git a/indoteknik_custom/models/account_report_general_ledger.py b/indoteknik_custom/models/account_report_general_ledger.py new file mode 100644 index 00000000..54e5bbd7 --- /dev/null +++ b/indoteknik_custom/models/account_report_general_ledger.py @@ -0,0 +1,226 @@ +from datetime import datetime +from dateutil.relativedelta import relativedelta +from odoo.exceptions import UserError +import json +from datetime import timedelta, date +import datetime +import io +from odoo import api, fields, models, _ +from odoo.tools.float_utils import float_round +from odoo.tools import date_utils +try: + from odoo.tools.misc import xlsxwriter +except ImportError: + import xlsxwriter + +class AccountReportGeneralLedger(models.TransientModel): + _inherit = "account.report.general.ledger.xlsx" + + journal_ids = fields.Many2many('account.journal', string=_('Journals'), required=True,default=lambda self: self.env['account.journal'].search([('id', '=', 10)])) + + def _build_contexts(self, data): + result = {} + result['journal_ids'] = 'journal_ids' in data['form'] and data['form']['journal_ids'] or False + result['state'] = 'target_move' in data['form'] and data['form']['target_move'] or '' + date_from = data['form']['date_from'] or False + + if date_from: + date_from = fields.Date.from_string(date_from) + + date_from -= relativedelta(days=1) + + result['date_from'] = fields.Date.to_string(date_from) + else: + result['date_from'] = False + + result['date_to'] = data['form']['date_to'] or False + result['strict_range'] = True if result['date_from'] else False + return result + + def check_report_ledger(self): + self.ensure_one() + data = {} + data['ids'] = self.env.context.get('active_ids', []) + data['model'] = self.env.context.get('active_model', 'ir.ui.menu') + data['form'] = self.read(['date_from', 'date_to', 'journal_ids', 'target_move'])[0] + used_context = self._build_contexts(data) + data['form']['used_context'] = dict(used_context, lang=self.env.context.get('lang') or 'en_US') + return { + 'type': 'ir.actions.report', + 'data': {'model': 'account.report.general.ledger.xlsx', + 'options': json.dumps(data, default=date_utils.json_default), + 'output_format': 'xlsx', + 'report_name': 'general ledger report', + }, + 'report_type': 'xlsx' + } + + def get_xlsx_report(self, options, response): + output = io.BytesIO() + workbook = xlsxwriter.Workbook(output, {'in_memory': True}) + data = {} + vals = self.search([('id', '=', options['form']['id'])]) + data['form'] = vals.read([])[0] + data['model'] = 'ir.ui.menu' + data['ids'] = [] + data['form']['used_context'] = { + 'date_to': options['form'].get('date_to', False), + 'date_from': options['form'].get('date_from', False), + 'strict_range': True, + 'state': options['form']['target_move'], + 'journal_ids': options['form']['journal_ids'], + } + + env_obj = vals.env['report.account.report_generalledger'] + sortby = data['form'].get('sortby', 'sort_date') + display_account = data['form']['display_account'] + codes = [] + if data['form'].get('journal_ids', False): + codes = [journal.code for journal in self.env['account.journal'].search([('id', 'in', data['form']['journal_ids'])])] + # accounts = vals.active_account if vals.active_account else self.env['account.account'].search([]) + accounts = self.env['account.account'].browse(options['ids']) or self.env['account.account'].search([]) + init_balance = vals['initial_balance'] + date_from = options['form'].get('date_from', False) + date_to = options['form'].get('date_to', False) + report_obj = env_obj.with_context(data['form'].get('used_context', {}))._get_account_move_entry_custom( + accounts, init_balance, sortby, display_account) + sheet = workbook.add_worksheet() + format1 = workbook.add_format({'font_size': 16, 'align': 'center', 'bg_color': '#D3D3D3', 'bold': True}) + format1.set_font_color('#000080') + format2 = workbook.add_format({'font_size': 12, 'bold': True, 'bg_color': '#D3D3D3'}) + format3 = workbook.add_format({'font_size': 10, 'bold': True}) + format4 = workbook.add_format({'font_size': 10}) + format6 = workbook.add_format({'font_size': 10, 'bold': True}) + format7 = workbook.add_format({'font_size': 10, 'align': 'center'}) + format5 = workbook.add_format({'font_size': 10, 'align': 'right'}) + format1.set_align('center') + format2.set_align('center') + format3.set_align('right') + format4.set_align('left') + codes = [] + if data['form'].get('journal_ids', False): + codes = [journal.code for journal in + self.env['account.journal'].search([('id', 'in', data['form']['journal_ids'])])] + logged_users = self.env['res.company']._company_default_get('account.account') + report_date = datetime.datetime.now().strftime("%Y-%m-%d") + sheet.merge_range('M8:N8', _("Report Date"), format3) + sheet.merge_range('M9:N9', report_date, format4) + sheet.merge_range(1, 0, 1, 14, logged_users.name, format4) + sheet.merge_range(3, 0, 4, 14, _("General Ledger Report"), format1) + sheet.merge_range('A6:B6', _("Journals :"), format6) + + row = 6 + col = 0 + i = 0 + for values in codes: + sheet.write(row, col + i, values, format7) + i += 1 + if data['form']['display_account'] == 'all': + display_account = _('All accounts') + elif data['form']['display_account'] == 'movement': + display_account = _('With movements') + else: + display_account = _('With balance not equal to zero') + + if data['form']['target_move'] == 'all': + target_moves = _('All entries') + else: + target_moves = _('All posted entries') + + if data['form']['sortby'] == 'sort_date': + sortby = 'Date' + else: + sortby = 'Journal and partners' + if data['form']['date_from']: + date_start = datetime.datetime.strptime(str(data['form']['used_context']['date_from']), '%Y-%m-%d') + date_start = date_start.strftime('%Y-%m-%d') + else: + date_start = "" + if data['form']['date_to']: + date_end = datetime.datetime.strptime(str(data['form']['used_context']['date_to']), '%Y-%m-%d') + date_end = date_end.strftime('%Y-%m-%d') + else: + date_end = "" + if sortby == 'Date': + sheet.write('G8', _("Start Date"), format3) + sheet.write('G9', date_start, format4) + sheet.write('J8', _("End Date"), format3) + sheet.write('J9', date_end, format4) + sheet.merge_range('C8:D8', _("Sorted By"), format3) + sheet.merge_range('C9:D9', sortby, format4) + sheet.merge_range('A8:B8', _("Display Account"), format6) + sheet.merge_range('A9:B9', display_account, format7) + sheet.merge_range('E8:F8', _("Target Moves"), format6) + sheet.merge_range('E9:F9', target_moves, format7) + sheet.write('A11', "Date ", format2) + sheet.write('B11', "JRNL", format2) + sheet.merge_range('C11:D11', _("Partner"), format2) + sheet.merge_range('E11:F11', _("Ref"), format2) + sheet.merge_range('G11:H11', _("Move"), format2) + sheet.merge_range('I11:L11', _("Entry Label"), format2) + sheet.write('M11', _("Debit"), format2) + sheet.write('N11', _("Credit"), format2) + sheet.write('O11', _("Balance"), format2) + sheet.write('P11', _("Debit Month"), format2) + sheet.write('Q11', _("Credit Month"), format2) + sheet.write('R11', _("Balance Month"), format2) + accounts = self.env['account.account'].search([]) + row_number = 11 + col_number = 0 + for account in accounts: + for values in report_obj: + if account['name'] == values['name'] and account['company_id'].id == values['company_id']: + sheet.write(row_number, col_number, account['code'], format3) + sheet.merge_range(row_number, col_number + 1, row_number, col_number + 11, account['name'], format6) + sheet.write(row_number, col_number + 12, + logged_users.currency_id.symbol + ' ' + "{:,.2f}".format(values['debit']), format3) + sheet.write(row_number, col_number + 13, + logged_users.currency_id.symbol + ' ' + "{:,.2f}".format(values['credit']), format3) + sheet.write(row_number, col_number + 14, + logged_users.currency_id.symbol + ' ' + "{:,.2f}".format(values['balance']), format3) + row_number += 1 + for lines in values['move_lines']: + if lines['ldate']: + formatted_date = datetime.datetime.strptime(str(lines['ldate']), '%Y-%m-%d') + formatted_date = formatted_date.strftime('%Y-%m-%d') + else: + formatted_date = "" + + sheet.write(row_number, col_number, formatted_date, format4) + sheet.write(row_number, col_number + 1, lines['lcode'], format4) + sheet.merge_range(row_number, col_number + 2, row_number, col_number + 3, lines['partner_name'], + format4) + sheet.merge_range(row_number, col_number + 4, row_number, col_number + 5, lines['lref'], + format4) + sheet.merge_range(row_number, col_number + 6, row_number, col_number + 7, lines['move_name'], + format4) + sheet.merge_range(row_number, col_number + 8, row_number, col_number + 11, lines['lname'], + format4) + sheet.write(row_number, col_number + 12, "{:,}".format(lines['debit']), format5) + sheet.write(row_number, col_number + 13, "{:,.2f}".format(lines['credit']), format5) + sheet.write(row_number, col_number + 14, "{:,.2f}".format(lines['balance']), format5) + + if lines['lname'] == 'Initial Balance': + debit_value = lines.get('debit', 0.0) + value_debit = values.get('debit', 0.0) + total_debit = value_debit - debit_value + debit_month = "{:,.2f}".format(total_debit) + + credit_value = lines.get('credit', 0.0) + value_credit = values.get('credit', 0.0) + total_credit = value_credit - credit_value + credit_month = "{:,.2f}".format(total_credit) + + total_balance = total_debit - total_credit + balance_month = "{:,.2f}".format(total_balance) + sheet.write(row_number, col_number + 15, debit_month, format5) + sheet.write(row_number, col_number + 16, credit_month, format5) + sheet.write(row_number, col_number + 17, balance_month, format5) + + row_number += 1 + + workbook.close() + output.seek(0) + response.stream.write(output.read()) + output.close() + diff --git a/indoteknik_custom/models/airway_bill_manifest.py b/indoteknik_custom/models/airway_bill_manifest.py index a606c2be..2da60f27 100644 --- a/indoteknik_custom/models/airway_bill_manifest.py +++ b/indoteknik_custom/models/airway_bill_manifest.py @@ -5,7 +5,7 @@ _logger = logging.getLogger(__name__) class AirwayBillManifest(models.Model): _name = 'airway.bill.manifest' - _description = 'Airway B ill Line' + _description = 'Airway Bill Line' _order = 'waybill_id, id' waybill_id = fields.Many2one('airway.bill', string='Airway Ref', required=True, ondelete='cascade', index=True, copy=False) @@ -19,7 +19,10 @@ class AirwayBillManifest(models.Model): try: history = waybill.decode_response() manifests = history['rajaongkir']['result']['manifest'] or [] - for manifest in manifests: + + sorted_manifests = sorted(manifests, key=lambda x: x['manifest_date'] + ' ' + x['manifest_time'], reverse=True) + + for manifest in sorted_manifests: code = manifest['manifest_code'] description = manifest['manifest_description'] date = manifest['manifest_date'] @@ -29,8 +32,8 @@ class AirwayBillManifest(models.Model): 'waybill_id': waybill.id, 'code': code, 'description': description, - 'datetime': date+' '+time, + 'datetime': date + ' ' + time, 'city': city, }) except: - return
\ No newline at end of file + return diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 7091bb72..d73f9037 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -187,13 +187,21 @@ class PurchaseOrder(models.Model): def button_confirm(self): res = super(PurchaseOrder, self).button_confirm() + if self.total_percent_margin < self.total_so_percent_margin and not self.env.user.is_purchasing_manager and not self.env.user.is_leader: raise UserError("Beda Margin dengan Sales, harus approval Manager") if not self.sale_order_id and not self.env.user.is_purchasing_manager and not self.env.user.is_leader: raise UserError("Tidak ada link dengan SO, harus approval Manager") + send_email = False for line in self.order_line: if not line.product_id.purchase_ok: - raise UserError("Terdapat barang yang tidak bisa di proses") + raise UserError("Terdapat barang yang tidak bisa diproses") + if line.price_vendor != 0 and line.price_unit != line.price_vendor: + send_email = True + break + + if send_email: + self._send_mail() self.approval_status = 'approved' self.po_status = 'menunggu' @@ -206,6 +214,11 @@ class PurchaseOrder(models.Model): self.date_planned = delta_time return res + + def _send_mail(self): + template_id = self.env.ref('indoteknik_custom.mail_template_po_sync_price').id + template = self.env['mail.template'].browse(template_id) + template.send_mail(self.id, force_send=True) def po_approve(self): if self.env.user.is_leader or self.env.user.is_purchasing_manager: diff --git a/indoteknik_custom/models/purchase_order_line.py b/indoteknik_custom/models/purchase_order_line.py index f255095f..39aeba0f 100755 --- a/indoteknik_custom/models/purchase_order_line.py +++ b/indoteknik_custom/models/purchase_order_line.py @@ -28,6 +28,21 @@ class PurchaseOrderLine(models.Model): qty_outgoing = fields.Float('Qty Outgoing', compute='compute_qty_stock') qty_available_store = fields.Float(string='Available') suggest = fields.Char(string='Suggest') + price_vendor = fields.Float(string='Price Vendor', compute='compute_price_vendor') + + def compute_price_vendor(self): + for line in self: + purchase_pricelist = self.env['purchase.pricelist'].search([ + ('product_id', '=', line.product_id.id), + ('vendor_id', '=', line.order_id.partner_id.id) + ], limit=1) + + if purchase_pricelist: + price_vendor = format(purchase_pricelist.product_price, ".2f") + price_vendor = float(price_vendor) + line.price_vendor = price_vendor + else: + line.price_vendor = 0 def compute_qty_stock(self): for line in self: diff --git a/indoteknik_custom/views/account_financial_report_view.xml b/indoteknik_custom/views/account_financial_report_view.xml new file mode 100644 index 00000000..7c156599 --- /dev/null +++ b/indoteknik_custom/views/account_financial_report_view.xml @@ -0,0 +1,51 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + + <record id="account_financial_report_view_custom" model="ir.ui.view"> + <field name="name">Common Report</field> + <field name="model">accounting.report.xlsx</field> + <field name="arch" type="xml"> + <form string="Report Options"> + <group col="4"> + <field name="account_report_id" domain="[('parent_id','=',False)]"/> + <field name="target_move" widget="radio"/> + <field name="enable_filter"/> + <field name="debit_credit" attrs="{'invisible': [('enable_filter','=',True)]}"/> + <field name="date_from"/> + <field name="date_to"/> + </group> + <group> + <notebook tabpos="up" colspan="4"> + <page string="Comparison" name="comparison" attrs="{'invisible': [('enable_filter','=',False)]}"> + <group> + <field name="label_filter" attrs="{'required': [('enable_filter', '=', True)]}"/> + <field name="filter_cmp"/> + </group> + <group string="Dates" attrs="{'invisible':[('filter_cmp', '!=', 'filter_date')]}"> + <field name="date_from_cmp" attrs="{'required':[('filter_cmp', '=', 'filter_date')]}"/> + <field name="date_to_cmp" attrs="{'required':[('filter_cmp', '=', 'filter_date')]}"/> + </group> + </page> + </notebook> + <field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/> + </group> + <footer> + <button name="check_report" string="Print" type="object" default_focus="1" class="oe_highlight"/> + <button string="Cancel" class="btn btn-secondary" special="cancel" /> + </footer> + </form> + </field> + </record> + + <record id="action_account_report_custom" model="ir.actions.act_window"> + <field name="name">Financial Reports</field> + <field name="res_model">accounting.report.xlsx</field> + <field name="type">ir.actions.act_window</field> + <field name="view_mode">form</field> + <field name="view_id" ref="account_financial_report_view_custom"/> + <field name="target">new</field> + </record> + + <menuitem id="menu_account_report" name="Financial Report" action="action_account_report_custom" parent="account.menu_finance_reports" sequence="250"/> + +</odoo> diff --git a/indoteknik_custom/views/account_report_general_ledger_view.xml b/indoteknik_custom/views/account_report_general_ledger_view.xml new file mode 100644 index 00000000..61c0ffff --- /dev/null +++ b/indoteknik_custom/views/account_report_general_ledger_view.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <record id="account_report_export_ledger_custom_view" model="ir.ui.view"> + <field name="name">Export Ledger</field> + <field name="model">account.report.general.ledger.xlsx</field> + <field name="arch" type="xml"> + <form string="Report Options"> + <field name="company_id" invisible="1"/> + <group col="4"> + <field name="target_move" widget="radio"/> + <field name="sortby" widget="radio"/> + <field name="display_account" widget="radio"/> + <field name="initial_balance"/> + <field name="date_from"/> + <field name="date_to"/> + </group> + <group> + <field name="journal_ids" widget="many2many_tags"/> + </group> + <footer> + <button name="check_report_ledger" string="Print" type="object" default_focus="1" class="oe_highlight"/> + <button string="Cancel" class="btn btn-default" special="cancel" /> + </footer> + </form> + </field> + </record> + + <record id="action_account_report_export_ledger_custom_menu" model="ir.actions.act_window"> + <field name="name">export_ledger</field> + <field name="res_model">account.report.general.ledger.xlsx</field> + <field name="view_mode">form</field> + <field name="view_id" ref="account_report_export_ledger_custom_view"/> + <field name="target">new</field> + </record> + +<menuitem id="menu_export_ledger_custom" name="General Ledger Export" action="action_account_report_export_ledger_custom_menu" parent="account.menu_finance_reports" sequence="250"/> +</odoo>
\ No newline at end of file diff --git a/indoteknik_custom/views/mail_template_po.xml b/indoteknik_custom/views/mail_template_po.xml new file mode 100644 index 00000000..410520b3 --- /dev/null +++ b/indoteknik_custom/views/mail_template_po.xml @@ -0,0 +1,86 @@ +<?xml version="1.0" ?> +<odoo> + <data noupdate="0"> + <record id="mail_template_po_sync_price" model="mail.template"> + <field name="name">PO: Sync Unit Price Purchase Pricelist</field> + <field name="model_id" ref="model_purchase_order" /> + <field name="subject">Your PO ${object.name}</field> + <field name="email_from"></field> + <field name="email_to">darren@indoteknik.co.id</field> + <field name="body_html" type="html"> + <table border="0" cellpadding="0" cellspacing="0" + style="padding-top: 16px; background-color: #F1F1F1; font-family:Verdana, Arial,sans-serif; color: #454748; width: 100%; border-collapse:separate;"> + <tr> + <td align="center"> + <table border="0" cellpadding="0" cellspacing="0" width="590" + style="padding: 16px; background-color: white; color: #454748; border-collapse:separate;"> + <tbody> + <!-- HEADER --> + <tr> + <td align="center" style="min-width: 590px;"> + <table border="0" cellpadding="0" cellspacing="0" width="590" + style="min-width: 590px; background-color: white; padding: 0px 8px 0px 8px; border-collapse:separate;"> + <tr> + <td valign="middle"> + <span style="font-size: 10px;">PO</span><br /> + <span style="font-size: 20px; font-weight: bold;"> + ${object.name} + </span> + </td> + </tr> + <tr> + <td colspan="2" style="text-align:center;"> + <hr width="100%" + style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin: 16px 0px 16px 0px;" /> + </td> + </tr> + </table> + </td> + </tr> + <!-- CONTENT --> + <tr> + <td align="center" style="min-width: 590px;"> + <table border="0" cellpadding="0" cellspacing="0" width="590" + style="min-width: 590px; background-color: white; padding: 0px 8px 0px 8px; border-collapse:separate;"> + <tr> + <td valign="top" style="font-size: 13px;"> + <div> + Dear Stefanus Darren, + <br/><br/> + Terdapat PO yang harga Unit Price nya tidak sama dengan yang ada di purchase pricelist nya. + <br/><br/> + Berikut adalah rincian PO: + % for line in object.order_line: + % if line.price_vendor != 0 and line.price_unit != line.price_vendor + <ul> + <li>Nama Produk: ${line.product_id.name}</li> + <li>Harga Unit dalam PO: Rp ${'{:,.2f}'.format(line.price_unit)}</li> + <li>Harga Unit dalam Purchase Pricelist: Rp ${'{:,.2f}'.format(line.price_vendor)}</li> + </ul> + % endif + % endfor + Silahkan periksa dan lakukan koreksi jika diperlukan. + <br/><br/> + Terima kasih. + </div> + </td> + </tr> + <tr> + <td style="text-align:center;"> + <hr width="100%" + style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin: 16px 0px 16px 0px;" /> + </td> + </tr> + </table> + </td> + </tr> + </tbody> + </table> + </td> + </tr> + </table> + </field> + <field name="auto_delete" eval="True" /> + </record> + </data> +</odoo>
\ No newline at end of file diff --git a/indoteknik_custom/views/purchase_order.xml b/indoteknik_custom/views/purchase_order.xml index 2f8590f3..7d436c46 100755 --- a/indoteknik_custom/views/purchase_order.xml +++ b/indoteknik_custom/views/purchase_order.xml @@ -56,6 +56,9 @@ <field name="qty_available_store"/> <field name="suggest"/> </field> + <field name="price_unit" position="after"> + <field name="price_vendor" attrs="{'readonly': 1}" optional="hide"/> + </field> <page name="purchase_delivery_invoice" position="after"> <page name="purchase_vendor_bills" string="Vendor Bills" groups="indoteknik_custom.technical_administrator"> <group> diff --git a/indoteknik_custom/views/raja_ongkir.xml b/indoteknik_custom/views/raja_ongkir.xml index 9e24a889..8888366b 100644 --- a/indoteknik_custom/views/raja_ongkir.xml +++ b/indoteknik_custom/views/raja_ongkir.xml @@ -68,125 +68,127 @@ action="rajaongkir_kurir_action" /> - <record id="rajaongkir_jne" model="rajaongkir.kurir"> - <field name="name">jne</field> - <field name="delivery_carrier_id">51</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_pos" model="rajaongkir.kurir"> - <field name="name">pos</field> - <field name="delivery_carrier_id">53</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_tiki" model="rajaongkir.kurir"> - <field name="name">tiki</field> - <field name="delivery_carrier_id">54</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_rpx" model="rajaongkir.kurir"> - <field name="name">rpx</field> - <field name="delivery_carrier_id">55</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_pandu" model="rajaongkir.kurir"> - <field name="name">pandu</field> - <field name="delivery_carrier_id">56</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_wahana" model="rajaongkir.kurir"> - <field name="name">wahana</field> - <field name="delivery_carrier_id">7</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_sicepat" model="rajaongkir.kurir"> - <field name="name">sicepat</field> - <field name="delivery_carrier_id">27</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_jnt" model="rajaongkir.kurir"> - <field name="name">jnt</field> - <field name="delivery_carrier_id">57</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_pahala" model="rajaongkir.kurir"> - <field name="name">pahala</field> - <field name="delivery_carrier_id">58</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_sap" model="rajaongkir.kurir"> - <field name="name">sap</field> - <field name="delivery_carrier_id">59</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_jet" model="rajaongkir.kurir"> - <field name="name">jet</field> - <field name="delivery_carrier_id">60</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_indah" model="rajaongkir.kurir"> - <field name="name">indah</field> - <field name="delivery_carrier_id">61</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_dse" model="rajaongkir.kurir"> - <field name="name">dse</field> - <field name="delivery_carrier_id">62</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_slis" model="rajaongkir.kurir"> - <field name="name">slis</field> - <field name="delivery_carrier_id">63</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_first" model="rajaongkir.kurir"> - <field name="name">first</field> - <field name="delivery_carrier_id">64</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_ncs" model="rajaongkir.kurir"> - <field name="name">ncs</field> - <field name="delivery_carrier_id">65</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_star" model="rajaongkir.kurir"> - <field name="name">star</field> - <field name="delivery_carrier_id">66</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_lion" model="rajaongkir.kurir"> - <field name="name">lion</field> - <field name="delivery_carrier_id">67</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_idl" model="rajaongkir.kurir"> - <field name="name">idl</field> - <field name="delivery_carrier_id">68</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_rex" model="rajaongkir.kurir"> - <field name="name">rex</field> - <field name="delivery_carrier_id">69</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_ide" model="rajaongkir.kurir"> - <field name="name">ide</field> - <field name="delivery_carrier_id">70</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_sentral" model="rajaongkir.kurir"> - <field name="name">sentral</field> - <field name="delivery_carrier_id">71</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_anteraja" model="rajaongkir.kurir"> - <field name="name">anteraja</field> - <field name="delivery_carrier_id">72</field> - <field name="publish">True</field> - </record> - <record id="rajaongkir_jtl" model="rajaongkir.kurir"> - <field name="name">jtl</field> - <field name="delivery_carrier_id">73</field> - <field name="publish">True</field> - </record> + <data noupdate="1"> + <record id="rajaongkir_jne" model="rajaongkir.kurir"> + <field name="name">jne</field> + <field name="delivery_carrier_id">51</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_pos" model="rajaongkir.kurir"> + <field name="name">pos</field> + <field name="delivery_carrier_id">53</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_tiki" model="rajaongkir.kurir"> + <field name="name">tiki</field> + <field name="delivery_carrier_id">54</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_rpx" model="rajaongkir.kurir"> + <field name="name">rpx</field> + <field name="delivery_carrier_id">55</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_pandu" model="rajaongkir.kurir"> + <field name="name">pandu</field> + <field name="delivery_carrier_id">56</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_wahana" model="rajaongkir.kurir"> + <field name="name">wahana</field> + <field name="delivery_carrier_id">7</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_sicepat" model="rajaongkir.kurir"> + <field name="name">sicepat</field> + <field name="delivery_carrier_id">27</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_jnt" model="rajaongkir.kurir"> + <field name="name">jnt</field> + <field name="delivery_carrier_id">57</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_pahala" model="rajaongkir.kurir"> + <field name="name">pahala</field> + <field name="delivery_carrier_id">58</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_sap" model="rajaongkir.kurir"> + <field name="name">sap</field> + <field name="delivery_carrier_id">59</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_jet" model="rajaongkir.kurir"> + <field name="name">jet</field> + <field name="delivery_carrier_id">60</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_indah" model="rajaongkir.kurir"> + <field name="name">indah</field> + <field name="delivery_carrier_id">61</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_dse" model="rajaongkir.kurir"> + <field name="name">dse</field> + <field name="delivery_carrier_id">62</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_slis" model="rajaongkir.kurir"> + <field name="name">slis</field> + <field name="delivery_carrier_id">63</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_first" model="rajaongkir.kurir"> + <field name="name">first</field> + <field name="delivery_carrier_id">64</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_ncs" model="rajaongkir.kurir"> + <field name="name">ncs</field> + <field name="delivery_carrier_id">65</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_star" model="rajaongkir.kurir"> + <field name="name">star</field> + <field name="delivery_carrier_id">66</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_lion" model="rajaongkir.kurir"> + <field name="name">lion</field> + <field name="delivery_carrier_id">67</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_idl" model="rajaongkir.kurir"> + <field name="name">idl</field> + <field name="delivery_carrier_id">68</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_rex" model="rajaongkir.kurir"> + <field name="name">rex</field> + <field name="delivery_carrier_id">69</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_ide" model="rajaongkir.kurir"> + <field name="name">ide</field> + <field name="delivery_carrier_id">70</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_sentral" model="rajaongkir.kurir"> + <field name="name">sentral</field> + <field name="delivery_carrier_id">71</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_anteraja" model="rajaongkir.kurir"> + <field name="name">anteraja</field> + <field name="delivery_carrier_id">72</field> + <field name="publish">True</field> + </record> + <record id="rajaongkir_jtl" model="rajaongkir.kurir"> + <field name="name">jtl</field> + <field name="delivery_carrier_id">73</field> + <field name="publish">True</field> + </record> + </data> </odoo>
\ No newline at end of file |
