diff --git a/bahmni_account/__init__.py b/bahmni_account/__init__.py index 50bdf71..0650744 100644 --- a/bahmni_account/__init__.py +++ b/bahmni_account/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- from . import models -# ~ from . import report diff --git a/bahmni_account/__manifest__.py b/bahmni_account/__manifest__.py index 69adf75..71e768d 100644 --- a/bahmni_account/__manifest__.py +++ b/bahmni_account/__manifest__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- { 'name': 'Bahmni Account', 'version': '1.0', @@ -13,11 +12,8 @@ 'images': [], 'depends': ['account'], 'data': [ - 'views/bahmni_account.xml', 'views/account_invoice_view.xml', - 'views/account_config_settings.xml', 'views/company_view.xml', - 'views/account_payment.xml', ], 'demo': [], 'qweb': [], diff --git a/bahmni_account/data/discount_accounts.xml b/bahmni_account/data/discount_accounts.xml deleted file mode 100644 index eb196ab..0000000 --- a/bahmni_account/data/discount_accounts.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - Discount - - - - - Overcharge - - - \ No newline at end of file diff --git a/bahmni_account/doc/ChangeLog.txt b/bahmni_account/doc/ChangeLog.txt deleted file mode 100644 index 3848479..0000000 --- a/bahmni_account/doc/ChangeLog.txt +++ /dev/null @@ -1,19 +0,0 @@ -1. New fields added to account.invoice for applying discounts on invoices. - 1. Discount Type : None, Fixed, Percentage - 2. Discount : Total discount amount getting applied. - 3. Discount Percentage : If percentage type is selected, then for defining percentage. - - if discount type is selected as percentage, then discount field will be readonly, - as discount amount will get computed based on given percentage. - 4. Discount Account Head : Account from/to which discount amount will get credited or debited. -2. on change method is defined for discount percentage and invoice lines, to compute discount amount, when type percetage is selected. -3. Customer Invoices form is inherited, and footer is defined completely in new way, - as default footer class was not making form look good. -4. compute_amount method is overridden to change the logic of computing total of invoice, i.e. deduct discount amount from total. -5. create method of account_invoice_line is inherited to set value of discount field, - when invoice is created through Create Invoice button on Sale Order form. - As method which is getting called through that button, is creating invoice object first - and then one-by-one invoice lines are getting created. - 6. rouding.off class defined to set round_off_amount value in account_invoice and sale_order. - for calculating this value, configuration is provided to user under Sales > Configuration > Settings menu, - where user can set Round Off Value, this is the amount to which value has to get rounded off. - \ No newline at end of file diff --git a/bahmni_account/doc/imp_points.txt b/bahmni_account/doc/imp_points.txt deleted file mode 100644 index 52e8619..0000000 --- a/bahmni_account/doc/imp_points.txt +++ /dev/null @@ -1,3 +0,0 @@ -* rounding.off class is kept in bahmni_account module, as it is used in account_invoice and sale_order class. - bahmni_sale already has dependency of bahmni_account module, hence this class can be accessed in that module. - vice-versa won't happen; as it will be a round dependency. \ No newline at end of file diff --git a/bahmni_account/models/__init__.py b/bahmni_account/models/__init__.py index a0a3d02..5eef738 100644 --- a/bahmni_account/models/__init__.py +++ b/bahmni_account/models/__init__.py @@ -1,7 +1,4 @@ -# -*- coding: utf-8 -*- from . import rounding_off from . import account_invoice from . import account_invoice_line -from . import account_config_settings from . import res_company -from . import account_payment diff --git a/bahmni_account/models/account_config_settings.py b/bahmni_account/models/account_config_settings.py deleted file mode 100644 index 203ad3f..0000000 --- a/bahmni_account/models/account_config_settings.py +++ /dev/null @@ -1,14 +0,0 @@ -# -*- coding: utf-8 -*- -from odoo import models, fields, api - - -class AccountConfigSettings(models.TransientModel): - _inherit = 'res.config.settings' - - round_off_by = fields.Float(string="Round off by", related="company_id.round_off_by") - - def set_round_off_by_defaults(self): - return self.env['ir.values'].sudo().set_default( - 'res.config.settings', 'round_off_by', self.round_off_by) - - diff --git a/bahmni_account/models/account_invoice.py b/bahmni_account/models/account_invoice.py index cf66ea0..08f3424 100644 --- a/bahmni_account/models/account_invoice.py +++ b/bahmni_account/models/account_invoice.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from odoo import fields, models, api, _ from odoo.exceptions import UserError, ValidationError import logging @@ -14,27 +13,6 @@ class AccountInvoice(models.Model): _inherit = 'account.move' -# # overridden this method to deduct discounted amount from total of invoice - @api.depends('invoice_line_ids.price_subtotal','line_ids.tax_line_id.amount', - 'currency_id', 'company_id', 'date', 'move_type', 'discount') - def _compute_amount(self): - round_curr = self.currency_id.round - self.amount_untaxed = sum(line.price_subtotal for line in self.invoice_line_ids) - self.amount_tax = sum(line.price_total for line in self.invoice_line_ids) - sum(line.price_subtotal for line in self.invoice_line_ids) - amount_total = self.amount_untaxed + self.amount_tax - self.discount - self.round_off_amount = self.env['rounding.off'].round_off_value_to_nearest(amount_total) - self.amount_total = self.amount_untaxed + self.amount_tax - self.discount + self.round_off_amount - amount_total_company_signed = self.amount_total - amount_untaxed_signed = self.amount_untaxed - if self.currency_id and self.company_id and self.currency_id != self.company_id.currency_id: - currency_id = self.currency_id.with_context(date=self.date_invoice) - amount_total_company_signed = currency_id.compute(self.amount_total, self.company_id.currency_id) - amount_untaxed_signed = currency_id.compute(self.amount_untaxed, self.company_id.currency_id) - sign = self.move_type in ['in_refund', 'out_refund'] and -1 or 1 - self.amount_total_in_currency_signed = amount_total_company_signed * sign - self.amount_total_signed = self.amount_total * sign - self.amount_untaxed_signed = amount_untaxed_signed * sign - discount_type = fields.Selection([('none', 'No Discount'), ('fixed', 'Fixed'), ('percentage', 'Percentage')], @@ -45,7 +23,7 @@ def _compute_amount(self): disc_acc_id = fields.Many2one('account.account', string="Discount Account Head") round_off_amount = fields.Monetary(string="Round Off Amount", - compute=_compute_amount) + ) @api.onchange('invoice_line_ids') def onchange_invoice_lines(self): @@ -93,139 +71,42 @@ def _find_batch(self, product, qty, location, picking): message = ("Auto validation Failed
Reason: There are no Batches/Serial no's available for %s product") % (product.id,product.name) picking.message_post(body=message) return False - - def button_dummy(self): - return self._compute_amount() - - def action_move_create(self): - #This method is overriden to pass the Discount Journal Entry. - """ Creates invoice related analytics and financial move lines """ - account_move = self.env['account.move'] - - for inv in self: - if not inv.journal_id.sequence_id: - raise UserError(_('Please define sequence on the journal related to this invoice.')) - if not inv.invoice_line_ids: - raise UserError(_('Please create some invoice lines.')) - if inv.move_id: - continue - - ctx = dict(self._context, lang=inv.partner_id.lang) - - if not inv.date_invoice: - inv.with_context(ctx).write({'date_invoice': fields.Date.context_today(self)}) - company_currency = inv.company_id.currency_id - - # create move lines (one per invoice line + eventual taxes and analytic lines) - iml = inv.invoice_line_move_line_get() - iml += inv.tax_line_move_line_get() - - diff_currency = inv.currency_id != company_currency - # create one move line for the total and possibly adjust the other lines amount - total, total_currency, iml = inv.with_context(ctx).compute_invoice_totals(company_currency, iml) - - name = inv.name or '/' - if inv.payment_term_id: - totlines = inv.with_context(ctx).payment_term_id.with_context(currency_id=company_currency.id).compute(total, inv.date_invoice)[0] - res_amount_currency = total_currency - ctx['date'] = inv._get_currency_rate_date() - for i, t in enumerate(totlines): - if inv.currency_id != company_currency: - amount_currency = company_currency.with_context(ctx).compute(t[1], inv.currency_id) - else: - amount_currency = False - - # last line: add the diff - res_amount_currency -= amount_currency or 0 - if i + 1 == len(totlines): - amount_currency += res_amount_currency - - iml.append({ - 'type': 'dest', - 'name': name, - 'price': t[1], - 'account_id': inv.account_id.id, - 'date_maturity': t[0], - 'amount_currency': diff_currency and amount_currency, - 'currency_id': diff_currency and inv.currency_id.id, - 'invoice_id': inv.id - }) - else: - iml.append({ - 'type': 'dest', - 'name': name, - 'price': total, - 'account_id': inv.account_id.id, - 'date_maturity': inv.date_due, - 'amount_currency': diff_currency and total_currency, - 'currency_id': diff_currency and inv.currency_id.id, - 'invoice_id': inv.id - }) - part = self.env['res.partner']._find_accounting_partner(inv.partner_id) - line = [(0, 0, self.line_get_convert(l, part.id)) for l in iml] - line = inv.group_lines(iml, line) - - journal = inv.journal_id.with_context(ctx) - line = inv.finalize_invoice_move_lines(line) - date = inv.date or inv.date_invoice - move_vals = { - 'ref': inv.reference, - 'line_ids': line, - 'journal_id': journal.id, - 'date': date, - 'narration': inv.comment, - } - ctx['company_id'] = inv.company_id.id - ctx['invoice'] = inv - ctx_nolang = ctx.copy() - ctx_nolang.pop('lang', None) - move = account_move.with_context(ctx_nolang).create(move_vals) - #=============Customized code starts========= - if inv.discount: - if inv.type == 'out_refund': - move_line = move.line_ids.filtered(lambda l:l.name==inv.name) - move_line.credit -= inv.discount - move_line_vals = { - 'name':'Discount', - 'company_id':move.company_id.id, - 'account_id':inv.disc_acc_id.id, - 'credit':inv.discount, - 'date_maturity':date, - 'currency_id': diff_currency and inv.currency_id.id, - 'invoice_id': inv.id, - 'partner_id':move_line.partner_id.id, - 'move_id':move.id, - } - self.env['account.move.line'].create(move_line_vals) - - else: - move_line = move.line_ids.filtered(lambda l:l.name=='/') - move_line.debit -= inv.discount - move_line_vals = { - 'name':'Discount', - 'company_id':move.company_id.id, - 'account_id':inv.disc_acc_id.id, - 'debit':inv.discount, - 'date_maturity':date, - 'currency_id': diff_currency and inv.currency_id.id, - 'invoice_id': inv.id, - 'partner_id':move_line.partner_id.id, - 'move_id':move.id, - } - self.env['account.move.line'].create(move_line_vals) - #===========Customized code ends============= - # Pass invoice in context in method post: used if you want to get the same - # account move reference when creating the same invoice after a cancelled one: - move.post() - # make the invoice point to that move - vals = { - 'move_id': move.id, - 'date': date, - 'move_name': move.name, - } - inv.with_context(ctx).write(vals) + def button_dummy(self): return True + + + + + def action_post(self): + + for inv in self: + print("inv",inv.discount,inv.round_off_amount,inv.amount_total) + + find_val = (inv.amount_total - inv.discount ) + inv.round_off_amount + + print("find_val",find_val) + differnece_vals = inv.amount_total - find_val + print("differnece_vals",differnece_vals) + + + for move_line in inv.line_ids: + update = False + print("move_line",move_line.display_type) + if move_line.display_type =='payment_term': + move_line.debit = move_line.debit - differnece_vals + + + + moves_with_payments = self.filtered('payment_id') + other_moves = self - moves_with_payments + if moves_with_payments: + moves_with_payments.payment_id.action_post() + if other_moves: + other_moves._post(soft=False) + return False + + @api.model def _prepare_refund(self, invoice, date_invoice=None, date=None, description=None, journal_id=None): diff --git a/bahmni_account/models/account_invoice_line.py b/bahmni_account/models/account_invoice_line.py index cf0480d..9e5b69c 100644 --- a/bahmni_account/models/account_invoice_line.py +++ b/bahmni_account/models/account_invoice_line.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from odoo import models, api, fields diff --git a/bahmni_account/models/account_payment.py b/bahmni_account/models/account_payment.py deleted file mode 100644 index f14bb25..0000000 --- a/bahmni_account/models/account_payment.py +++ /dev/null @@ -1,46 +0,0 @@ -# -*- coding: utf-8 -*- -from itertools import groupby -from odoo import models, fields, api - -class AccountPayment(models.Model): - _inherit = 'account.payment' - - @api.onchange('partner_id', 'amount') - def _calculate_balances(self): - if(self.state != 'posted'): - partner = self.partner_id - balance = partner.credit or partner.debit - self.balance_before_pay = balance - self.total_balance = balance - self.amount - - @api.onchange('invoice_ids') - def onchange_partner_id(self): - if self.invoice_ids: - bill_amount = 0 - for inv in self.invoice_ids: - bill_amount += inv.amount_total - self.bill_amount = bill_amount - - @api.onchange('payment_type') - def _onchange_payment_type(self): - if not self.invoice_ids: - # Set default partner type for the payment type - if self.payment_type == 'inbound': - self.partner_type = 'customer' - elif self.payment_type == 'outbound': - self.partner_type = 'supplier' - else: - self.partner_type = False - # Set payment method domain - res = self._onchange_journal() - if not res.get('domain', {}): - res['domain'] = {} - res['domain']['journal_id'] = self.payment_type == 'inbound' and [('at_least_one_inbound', '=', True)] or self.payment_type == 'outbound' and [('at_least_one_outbound', '=', True)] or [] - return res - - balance_before_pay = fields.Float(compute=_calculate_balances, - string="Balance before pay") - total_balance = fields.Float(compute=_calculate_balances, - string="Total Balance") - invoice_id = fields.Many2one('account.invoice', string='Invoice') - bill_amount = fields.Float(string="Bill Amount") diff --git a/bahmni_account/models/res_company.py b/bahmni_account/models/res_company.py index 17ac2e4..b57016c 100644 --- a/bahmni_account/models/res_company.py +++ b/bahmni_account/models/res_company.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from odoo import models, fields diff --git a/bahmni_account/models/res_partner.py b/bahmni_account/models/res_partner.py deleted file mode 100644 index e9810b3..0000000 --- a/bahmni_account/models/res_partner.py +++ /dev/null @@ -1,8 +0,0 @@ -# -*- coding: utf-8 -*- -from odoo import models, fields - - -class ResPartner(models.Model): - _inherit = 'res.partner' - - initials = fields.Char(string="Initials") diff --git a/bahmni_account/models/rounding_off.py b/bahmni_account/models/rounding_off.py index e0a15cc..307f70c 100644 --- a/bahmni_account/models/rounding_off.py +++ b/bahmni_account/models/rounding_off.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from odoo import models, fields, api class RoundingOff(models.Model): diff --git a/bahmni_account/report/__init__.py b/bahmni_account/report/__init__.py deleted file mode 100644 index a3eab91..0000000 --- a/bahmni_account/report/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# -*- coding: utf-8 -*- -from . import account_count_report -from . import account_report diff --git a/bahmni_account/report/account_count_report.py b/bahmni_account/report/account_count_report.py deleted file mode 100644 index bc63e42..0000000 --- a/bahmni_account/report/account_count_report.py +++ /dev/null @@ -1,35 +0,0 @@ -# -*- coding: utf-8 -*- -from odoo import models, fields, api -from odoo.tools import drop_view_if_exists -from odoo.exceptions import Warning - - -class AccountCountReport(models.Model): - _name = 'account.count.report' - _auto = False - _description = "Count of account heads in sale orders over a period" - - count = fields.Integer(string="Count", readonly=True) - date = fields.Date(string="Date", readonly=True) - account_id = fields.Many2one('account.account', string="Account") - - # ~ @api.model_cr - def init(self): - drop_view_if_exists(self.env.cr, 'account_count_report') - self.env.cr.execute(""" - create or replace view account_count_report as ( - select - concat(ail.account_id, '_', ai.date) as id, - ai.date as date, - ail.account_id as account_id, - count(*) as count - from account_move ai, account_move_line ail - where - ail.move_id = ai.id - --and ai.type != 'out_refund' - group by ail.account_id, ai.date - )""") - - # ~ @api.multi - def unlink(self): - raise Warning('You cannot delete any record!') diff --git a/bahmni_account/report/account_count_report.xml b/bahmni_account/report/account_count_report.xml deleted file mode 100644 index 79248e9..0000000 --- a/bahmni_account/report/account_count_report.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - account.count.report.tree - account.count.report - - - - - - - - - - - account.count.report.filter - account.count.report - - - - - - - - - - - - - - - - - - Accounts Count Report - ir.actions.act_window - account.count.report - tree,form - - - {} - - - - - - diff --git a/bahmni_account/report/account_report.py b/bahmni_account/report/account_report.py deleted file mode 100644 index 3de56b3..0000000 --- a/bahmni_account/report/account_report.py +++ /dev/null @@ -1,78 +0,0 @@ -# -*- coding: utf-8 -*- -from odoo import models, fields, api -from odoo.tools import drop_view_if_exists - - -class AccountReport(models.Model): - _name ='bahmni.account.report' - _inherit = 'account.report' - _description = "Account reports for actual & received amount" - _auto = False - - actual_amount = fields.Integer(string="Expenses") - amount_received = fields.Integer(string="Collections") - date = fields.Date(string="Date") - account_id = fields.Many2one('account.account', string="Account Head") - - # ~ @api.model_cr - def init(self): - drop_view_if_exists(self.env.cr, 'bahmni_account_report') - self.env.cr.execute(""" - create or replace view bahmni_account_report as ( - (select id,date,account_id, sum(actual_amount) as actual_amount,sum(amount_received) as amount_received - from ( - SELECT - pg_catalog.concat(ail.account_id, '_', ai.date, '_', ai.move_type) AS id,ai.id as invoice_id, - ai.date AS date, - ail.account_id, - CASE - WHEN ai.move_type = 'out_refund' THEN 0 - ELSE sum(ail.price_subtotal) - END AS actual_amount, - CASE - WHEN ai.move_type = 'out_refund' THEN sum( - (-ail.price_subtotal) * (ai.amount_total / (ai.amount_tax + ai.amount_untaxed))) - ELSE sum(ail.price_subtotal * (ai.amount_total / (ai.amount_tax + ai.amount_untaxed))) - END AS amount_received - FROM account_move ai, account_move_line ail - WHERE ail.move_id = ai.id AND (ai.amount_tax + ai.amount_untaxed) <> 0 AND state = 'paid' - GROUP BY ail.account_id, ai.date, ai.move_type, ai.id - UNION - SELECT - pg_catalog.concat(ail.account_id, '_', ai.date, '_', ai.move_type) AS id,ai.id as invoice_id, - ai.date AS date, - ail.account_id, - CASE - WHEN ai.move_type = 'out_refund' THEN 0 - ELSE max(ai.amount_total) - END AS actual_amount, - CASE - WHEN ai.move_type = 'out_refund' THEN max(ai.amount_total) * -1 - ELSE max(ai.amount_total) - END AS amount_received - FROM account_move ai, account_move_line ail - WHERE ail.move_id = ai.id AND (ai.amount_tax + ai.amount_untaxed) = 0 AND state = 'paid' - and ail.account_id not in - (select id from account_account where name in ('FINE','Discount','Overcharge')) - GROUP BY ail.account_id, ai.date, ai.move_type,ai.id - UNION - SELECT - pg_catalog.concat(ail.account_id, '_', ai.date, '_', ai.move_type) AS id,ai.id as invoice_id, - ai.date AS date, - ail.account_id, - CASE - WHEN ai.move_type = 'out_refund' THEN 0 - ELSE sum(ai.amount_total) - END AS actual_amount, - CASE - WHEN ai.move_type = 'out_refund' THEN sum(-ai.amount_total) - ELSE sum(ai.amount_total) - END AS amount_received - FROM account_move ai, account_move_line ail - WHERE ail.move_id = ai.id AND (ai.amount_tax + ai.amount_untaxed) = 0 AND state = 'paid' - and ail.account_id in - (select id from account_account where name in ('FINE','Discount','Overcharge')) - GROUP BY ail.account_id, ai.date, ai.move_type,ai.id - ) as r group by id,date,account_id) - )""") - diff --git a/bahmni_account/report/account_report.xml b/bahmni_account/report/account_report.xml deleted file mode 100644 index 838cf4b..0000000 --- a/bahmni_account/report/account_report.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - account.report.tree - bahmni.account.report - - - - - - - - - - - - account.report.filter - bahmni.account.report - - - - - - - - - - - - - - - - - - Account Report - ir.actions.act_window - bahmni.account.report - tree,form - - - {} - - - - - diff --git a/bahmni_account/report/report_invoice_inherit.xml b/bahmni_account/report/report_invoice_inherit.xml deleted file mode 100644 index 7256f6b..0000000 --- a/bahmni_account/report/report_invoice_inherit.xml +++ /dev/null @@ -1,168 +0,0 @@ - - - - diff --git a/bahmni_account/views/account_config_settings.xml b/bahmni_account/views/account_config_settings.xml deleted file mode 100644 index 13d12b9..0000000 --- a/bahmni_account/views/account_config_settings.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - inherit.view.account.config.settings - res.config.settings - - - - - - - - - - diff --git a/bahmni_account/views/account_invoice_view.xml b/bahmni_account/views/account_invoice_view.xml index 1e9324d..36be75c 100644 --- a/bahmni_account/views/account_invoice_view.xml +++ b/bahmni_account/views/account_invoice_view.xml @@ -8,106 +8,46 @@ - - + + + + + - - - - - - - + + + -