Skip to content
Snippets Groups Projects
Commit afef12ad6333 authored by Houzefa Abbasbhay's avatar Houzefa Abbasbhay :slight_smile:
Browse files

Remove obsolete items:

* Partner "Invoiced" smart button changes: Never called; that was for a
  specific Odoo 10 project.
* Invoices & refunds - Show due date: No such changes anymore.
* Invoice validation override: The only changes were:

    * Missing due date filler: Odoo 10 migration defect, got forgotten.
    * Hook to change account-move creation values: No longer needed. Was for
      analytics but xcg/account_analytic_structure supersedes that part.
    * Reference link filler: Moved to xcg/account_move_reference_link.
parent 78404ff7afaa
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,3 @@
Improve Odoo invoices.
- Split the "Client invoices + refunds" menu command in 2.
- Client invoices & refunds: Show the due date.
- Clients: Tweak the "Invoiced" smart button.
# flake8: noqa
from . import models
# -*- coding: utf-8 -*-
##############################################################################
#
# Invoice improvements, for Odoo
......@@ -30,10 +29,6 @@
Improve Odoo invoices.
- Split the "Client invoices + refunds" menu command in 2.
- Client invoices & refunds: Show the due date.
- Clients: Tweak the "Invoiced" smart button.
""",
"website": "http://odoo.consulting/",
"init_xml": [],
......@@ -37,14 +32,9 @@
""",
"website": "http://odoo.consulting/",
"init_xml": [],
"depends": [
"base",
"account",
"account_analytic_structure",
"analytic_structure",
],
"depends": ["account"],
"data": ["views/account_invoice.xml"],
"test": [],
"installable": True,
"active": False,
}
......@@ -46,6 +36,5 @@
"data": ["views/account_invoice.xml"],
"test": [],
"installable": True,
"active": False,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
# flake8: noqa
from . import account_invoice, res_partner
import logging
from odoo import _, api, exceptions, fields, models
log = logging.getLogger(__name__)
class Invoice(models.Model):
"""Improve Odoo invoices:
- TODO Document features.
"""
# TODO Fill the above docstring.
_inherit = "account.invoice"
@api.multi
def _get_object_reference(self):
""" Set the move object reference to account_invoice
"""
return "account.invoice,%s" % self.id
@api.one
def get_move_vals(self, vals):
"""Helper to override, if specific data are to be injected, on
creation of an accounting document from an invoice.
"""
return vals
@api.multi
def action_move_create(self):
""" 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 exceptions.UserError(
_(
"Please define sequence on the journal related to "
"this invoice."
)
)
if not inv.invoice_line_ids:
raise exceptions.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.date or inv.date_invoice
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,
"object_reference": inv._get_object_reference(),
}
ctx["company_id"] = inv.company_id.id
ctx["invoice"] = inv
ctx_nolang = ctx.copy()
ctx_nolang.pop("lang", None)
move_vals = inv.get_move_vals(move_vals)[0]
move = account_move.with_context(ctx_nolang).create(move_vals)
# 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)
return True
from ast import literal_eval
from odoo import models
class Partner(models.Model):
"""Tweak the "Invoiced" smart button.
"""
_inherit = "res.partner"
def open_partner_history(self):
"""Called by the "Invoiced" smart button. Returns an Odoo action dict
to display invoices / refunds for specified partners.
Override this method defined in the "account" addon to:
- Reset a context key the "partner_contact_in_several_companies" OCA
addon may have added which would conflict with filters we want here.
- Include a context key read by invoice view filters.
"""
action = super(Partner, self).open_partner_history()
if not action:
return action
# Get the context from the Odoo action dict. It is a unicode instance
# as comes straight from a "read" call, so convert...
action_context = action.get("context") or {}
action_context_is_str = isinstance(action_context, str)
if action_context_is_str:
try:
action_context = literal_eval(action_context)
except ValueError:
action_context = {}
# Reset this context key the "partner_contact_in_several_companies" OCA
# addon may have added which would conflict with parent / child filters
# we want here.
action_context["search_show_all_positions"] = {}
# This context key will be read by invoice view filters (see
# views/account_invoice.xml).
action_context["from_partner_form"] = 1
# Serialize back for good form.
if action_context_is_str:
action["context"] = str(action_context)
return action
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment