mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[13.0][MIG] account_spread_cost_revenue
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# Copyright 2018-2019 Onestein (<https://www.onestein.eu>)
|
||||
# Copyright 2018-2020 Onestein (<https://www.onestein.eu>)
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
import calendar
|
||||
@@ -10,8 +10,6 @@ from odoo import _, api, fields, models
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
from odoo.tools import float_is_zero
|
||||
|
||||
from odoo.addons import decimal_precision as dp
|
||||
|
||||
|
||||
class AccountSpread(models.Model):
|
||||
_name = "account.spread"
|
||||
@@ -46,65 +44,64 @@ class AccountSpread(models.Model):
|
||||
help="Period length for the entries",
|
||||
required=True,
|
||||
)
|
||||
use_invoice_line_account = fields.Boolean(string="Use invoice line's account",)
|
||||
use_invoice_line_account = fields.Boolean()
|
||||
credit_account_id = fields.Many2one(
|
||||
"account.account", string="Credit Account", required=True
|
||||
"account.account",
|
||||
compute="_compute_credit_account_id",
|
||||
readonly=False,
|
||||
store=True,
|
||||
required=True,
|
||||
)
|
||||
debit_account_id = fields.Many2one(
|
||||
"account.account", string="Debit Account", required=True
|
||||
"account.account",
|
||||
compute="_compute_debit_account_id",
|
||||
readonly=False,
|
||||
store=True,
|
||||
required=True,
|
||||
)
|
||||
is_credit_account_deprecated = fields.Boolean(
|
||||
compute="_compute_deprecated_accounts"
|
||||
)
|
||||
is_debit_account_deprecated = fields.Boolean(compute="_compute_deprecated_accounts")
|
||||
unspread_amount = fields.Float(
|
||||
digits=dp.get_precision("Account"), compute="_compute_amounts"
|
||||
)
|
||||
unposted_amount = fields.Float(
|
||||
digits=dp.get_precision("Account"), compute="_compute_amounts"
|
||||
)
|
||||
posted_amount = fields.Float(
|
||||
digits=dp.get_precision("Account"), compute="_compute_amounts"
|
||||
)
|
||||
total_amount = fields.Float(
|
||||
digits=dp.get_precision("Account"), compute="_compute_amounts"
|
||||
)
|
||||
all_posted = fields.Boolean(compute="_compute_amounts", store=True)
|
||||
unspread_amount = fields.Float(digits="Account", compute="_compute_amounts",)
|
||||
unposted_amount = fields.Float(digits="Account", compute="_compute_amounts",)
|
||||
posted_amount = fields.Float(digits="Account", compute="_compute_amounts",)
|
||||
total_amount = fields.Float(digits="Account", compute="_compute_amounts",)
|
||||
all_posted = fields.Boolean(compute="_compute_all_posted", store=True)
|
||||
line_ids = fields.One2many(
|
||||
"account.spread.line", "spread_id", string="Spread Lines"
|
||||
)
|
||||
spread_date = fields.Date(
|
||||
string="Start Date", default=time.strftime("%Y-01-01"), required=True
|
||||
)
|
||||
journal_id = fields.Many2one("account.journal", string="Journal", required=True)
|
||||
journal_id = fields.Many2one(
|
||||
"account.journal",
|
||||
compute="_compute_journal_id",
|
||||
readonly=False,
|
||||
store=True,
|
||||
required=True,
|
||||
)
|
||||
invoice_line_ids = fields.One2many(
|
||||
"account.invoice.line", "spread_id", copy=False, string="Invoice Lines"
|
||||
"account.move.line", "spread_id", copy=False, string="Invoice Lines"
|
||||
)
|
||||
invoice_line_id = fields.Many2one(
|
||||
"account.invoice.line",
|
||||
"account.move.line",
|
||||
string="Invoice line",
|
||||
compute="_compute_invoice_line",
|
||||
inverse="_inverse_invoice_line",
|
||||
store=True,
|
||||
)
|
||||
invoice_id = fields.Many2one(
|
||||
related="invoice_line_id.invoice_id",
|
||||
readonly=True,
|
||||
store=True,
|
||||
string="Invoice",
|
||||
related="invoice_line_id.move_id", readonly=True, store=True,
|
||||
)
|
||||
estimated_amount = fields.Float(digits=dp.get_precision("Account"))
|
||||
estimated_amount = fields.Float(digits="Account")
|
||||
company_id = fields.Many2one(
|
||||
"res.company",
|
||||
default=lambda self: self.env.user.company_id,
|
||||
string="Company",
|
||||
required=True,
|
||||
"res.company", default=lambda self: self.env.company, required=True
|
||||
)
|
||||
currency_id = fields.Many2one(
|
||||
"res.currency",
|
||||
string="Currency",
|
||||
required=True,
|
||||
default=lambda self: self.env.user.company_id.currency_id.id,
|
||||
default=lambda self: self.env.company.currency_id.id,
|
||||
)
|
||||
account_analytic_id = fields.Many2one(
|
||||
"account.analytic.account", string="Analytic Account"
|
||||
@@ -112,10 +109,10 @@ class AccountSpread(models.Model):
|
||||
analytic_tag_ids = fields.Many2many("account.analytic.tag", string="Analytic Tags")
|
||||
move_line_auto_post = fields.Boolean("Auto-post lines", default=True)
|
||||
display_create_all_moves = fields.Boolean(
|
||||
compute="_compute_display_create_all_moves", string="Display Button All Moves"
|
||||
compute="_compute_display_create_all_moves",
|
||||
)
|
||||
display_recompute_buttons = fields.Boolean(
|
||||
compute="_compute_display_recompute_buttons", string="Display Buttons Recompute"
|
||||
compute="_compute_display_recompute_buttons",
|
||||
)
|
||||
display_move_line_auto_post = fields.Boolean(
|
||||
compute="_compute_display_move_line_auto_post",
|
||||
@@ -123,18 +120,19 @@ class AccountSpread(models.Model):
|
||||
)
|
||||
active = fields.Boolean(default=True)
|
||||
|
||||
@api.model
|
||||
def default_journal(self, company_id):
|
||||
domain = [("type", "=", "general"), ("company_id", "=", company_id)]
|
||||
return self.env["account.journal"].search(domain, limit=1)
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
res = super().default_get(fields)
|
||||
if "company_id" not in fields:
|
||||
company_id = self.env.user.company_id.id
|
||||
else:
|
||||
company_id = res["company_id"]
|
||||
default_journal = self.env["account.journal"].search(
|
||||
[("type", "=", "general"), ("company_id", "=", company_id)], limit=1
|
||||
)
|
||||
if "journal_id" not in res and default_journal:
|
||||
res["journal_id"] = default_journal.id
|
||||
if "journal_id" not in res:
|
||||
company_id = res.get("company_id", self.env.company.id)
|
||||
default_journal = self.default_journal(company_id)
|
||||
if default_journal:
|
||||
res["journal_id"] = default_journal.id
|
||||
return res
|
||||
|
||||
@api.depends("invoice_type")
|
||||
@@ -145,20 +143,16 @@ class AccountSpread(models.Model):
|
||||
else:
|
||||
spread.spread_type = "purchase"
|
||||
|
||||
@api.depends("invoice_line_ids", "invoice_line_ids.invoice_id")
|
||||
@api.depends("invoice_line_ids", "invoice_line_ids.move_id")
|
||||
def _compute_invoice_line(self):
|
||||
for spread in self:
|
||||
invoice_lines = spread.invoice_line_ids
|
||||
line = invoice_lines and invoice_lines[0] or False
|
||||
spread.invoice_line_id = line
|
||||
spread.invoice_line_id = invoice_lines and invoice_lines[0] or False
|
||||
|
||||
@api.multi
|
||||
def _inverse_invoice_line(self):
|
||||
for spread in self:
|
||||
invoice_line = spread.invoice_line_id
|
||||
spread.write(
|
||||
{"invoice_line_ids": [(6, 0, [invoice_line.id])],}
|
||||
)
|
||||
spread.write({"invoice_line_ids": [(6, 0, [invoice_line.id])]})
|
||||
|
||||
@api.depends(
|
||||
"estimated_amount",
|
||||
@@ -171,38 +165,36 @@ class AccountSpread(models.Model):
|
||||
)
|
||||
def _compute_amounts(self):
|
||||
for spread in self:
|
||||
moves_amount = 0.0
|
||||
posted_amount = 0.0
|
||||
lines_move = spread.line_ids.filtered(lambda l: l.move_id)
|
||||
moves_amount = sum(spread_line.amount for spread_line in lines_move)
|
||||
lines_posted = lines_move.filtered(lambda l: l.move_id.state == "posted")
|
||||
posted_amount = sum(spread_line.amount for spread_line in lines_posted)
|
||||
total_amount = spread.estimated_amount
|
||||
if spread.invoice_line_id:
|
||||
invoice = spread.invoice_line_id.invoice_id
|
||||
total_amount = spread.invoice_line_id.currency_id._convert(
|
||||
spread.invoice_line_id.price_subtotal,
|
||||
spread.invoice_line_id.balance,
|
||||
spread.currency_id,
|
||||
spread.company_id,
|
||||
invoice._get_currency_rate_date() or fields.Date.today(),
|
||||
spread.invoice_id.date,
|
||||
)
|
||||
|
||||
for spread_line in spread.line_ids:
|
||||
if spread_line.move_id:
|
||||
moves_amount += spread_line.amount
|
||||
if spread_line.move_id.state == "posted":
|
||||
posted_amount += spread_line.amount
|
||||
spread.unspread_amount = total_amount - moves_amount
|
||||
spread.unposted_amount = total_amount - posted_amount
|
||||
spread.posted_amount = posted_amount
|
||||
spread.total_amount = total_amount
|
||||
spread.all_posted = spread.unposted_amount == 0.0
|
||||
|
||||
@api.multi
|
||||
@api.depends("unposted_amount")
|
||||
def _compute_all_posted(self):
|
||||
for spread in self:
|
||||
rounding = self.currency_id.rounding
|
||||
unposted = spread.unposted_amount
|
||||
spread.all_posted = float_is_zero(unposted, precision_rounding=rounding)
|
||||
|
||||
def _compute_display_create_all_moves(self):
|
||||
for spread in self:
|
||||
if any(not line.move_id for line in spread.line_ids):
|
||||
spread.display_create_all_moves = True
|
||||
else:
|
||||
spread.display_create_all_moves = False
|
||||
any_not_move = any(not line.move_id for line in spread.line_ids)
|
||||
spread.display_create_all_moves = any_not_move
|
||||
|
||||
@api.multi
|
||||
def _compute_display_recompute_buttons(self):
|
||||
for spread in self:
|
||||
spread.display_recompute_buttons = True
|
||||
@@ -210,14 +202,12 @@ class AccountSpread(models.Model):
|
||||
if spread.invoice_id.state == "draft":
|
||||
spread.display_recompute_buttons = False
|
||||
|
||||
@api.multi
|
||||
@api.depends("company_id.force_move_auto_post")
|
||||
def _compute_display_move_line_auto_post(self):
|
||||
for spread in self:
|
||||
spread.display_move_line_auto_post = True
|
||||
if spread.company_id.force_move_auto_post:
|
||||
spread.display_move_line_auto_post = False
|
||||
auto_post = spread.company_id.force_move_auto_post
|
||||
spread.display_move_line_auto_post = not auto_post
|
||||
|
||||
@api.multi
|
||||
def _get_spread_entry_name(self, seq):
|
||||
"""Use this method to customise the name of the accounting entry."""
|
||||
self.ensure_one()
|
||||
@@ -239,66 +229,67 @@ class AccountSpread(models.Model):
|
||||
if self.template_id.start_date:
|
||||
self.spread_date = self.template_id.start_date
|
||||
|
||||
@api.onchange("invoice_type", "company_id")
|
||||
def onchange_invoice_type(self):
|
||||
company = self.company_id
|
||||
@api.depends("invoice_type", "company_id")
|
||||
def _compute_journal_id(self):
|
||||
if not self.env.context.get("default_journal_id"):
|
||||
journal = company.default_spread_expense_journal_id
|
||||
if self.invoice_type in ("out_invoice", "in_refund"):
|
||||
journal = company.default_spread_revenue_journal_id
|
||||
if journal:
|
||||
self.journal_id = journal
|
||||
for spread in self:
|
||||
journal = spread.company_id.default_spread_expense_journal_id
|
||||
if spread.invoice_type in ("out_invoice", "in_refund"):
|
||||
journal = spread.company_id.default_spread_revenue_journal_id
|
||||
if not journal:
|
||||
journal = self.default_journal(spread.company_id.id)
|
||||
spread.journal_id = journal
|
||||
|
||||
@api.depends("invoice_type", "company_id")
|
||||
def _compute_debit_account_id(self):
|
||||
if not self.env.context.get("default_debit_account_id"):
|
||||
if self.invoice_type in ("out_invoice", "in_refund"):
|
||||
debit_account_id = company.default_spread_revenue_account_id
|
||||
self.debit_account_id = debit_account_id
|
||||
invoice_types = ("out_invoice", "in_refund")
|
||||
for spread in self.filtered(lambda s: s.invoice_type in invoice_types):
|
||||
debit_account = spread.company_id.default_spread_revenue_account_id
|
||||
spread.debit_account_id = debit_account
|
||||
|
||||
@api.depends("invoice_type", "company_id")
|
||||
def _compute_credit_account_id(self):
|
||||
if not self.env.context.get("default_credit_account_id"):
|
||||
if self.invoice_type in ("in_invoice", "out_refund"):
|
||||
credit_account_id = company.default_spread_expense_account_id
|
||||
self.credit_account_id = credit_account_id
|
||||
invoice_types = ("in_invoice", "out_refund")
|
||||
for spread in self.filtered(lambda s: s.invoice_type in invoice_types):
|
||||
credit_account = spread.company_id.default_spread_expense_account_id
|
||||
spread.credit_account_id = credit_account
|
||||
|
||||
@api.constrains("invoice_id", "invoice_type")
|
||||
def _check_invoice_type(self):
|
||||
for spread in self:
|
||||
if not spread.invoice_id:
|
||||
pass
|
||||
elif spread.invoice_type != spread.invoice_id.type:
|
||||
raise ValidationError(
|
||||
_("The Invoice Type does not correspond to the Invoice")
|
||||
)
|
||||
if self.filtered(
|
||||
lambda s: s.invoice_id and s.invoice_type != s.invoice_id.type
|
||||
):
|
||||
raise ValidationError(
|
||||
_("The Invoice Type does not correspond to the Invoice")
|
||||
)
|
||||
|
||||
@api.constrains("journal_id")
|
||||
def _check_journal(self):
|
||||
for spread in self:
|
||||
moves = spread.mapped("line_ids.move_id").filtered("journal_id")
|
||||
if any(move.journal_id != spread.journal_id for move in moves):
|
||||
raise ValidationError(
|
||||
_("The Journal is not consistent with the account moves.")
|
||||
)
|
||||
err_msg = _("The Journal is not consistent with the account moves.")
|
||||
raise ValidationError(err_msg)
|
||||
|
||||
@api.constrains("template_id", "invoice_type")
|
||||
def _check_template_invoice_type(self):
|
||||
for spread in self:
|
||||
for spread in self.filtered(lambda s: s.template_id.spread_type == "sale"):
|
||||
if spread.invoice_type in ["in_invoice", "in_refund"]:
|
||||
if spread.template_id.spread_type == "sale":
|
||||
raise ValidationError(
|
||||
_(
|
||||
"The Spread Template (Sales) is not compatible "
|
||||
"with selected invoice type"
|
||||
)
|
||||
)
|
||||
elif spread.invoice_type in ["out_invoice", "out_refund"]:
|
||||
if spread.template_id.spread_type == "purchase":
|
||||
raise ValidationError(
|
||||
_(
|
||||
"The Spread Template (Purchases) is not compatible "
|
||||
"with selected invoice type"
|
||||
)
|
||||
)
|
||||
err_msg = _(
|
||||
"The Spread Template (Sales) is not compatible "
|
||||
"with selected invoice type"
|
||||
)
|
||||
raise ValidationError(err_msg)
|
||||
for spread in self.filtered(lambda s: s.template_id.spread_type == "purchase"):
|
||||
if spread.invoice_type in ["out_invoice", "out_refund"]:
|
||||
err_msg = _(
|
||||
"The Spread Template (Purchases) is not compatible "
|
||||
"with selected invoice type"
|
||||
)
|
||||
raise ValidationError(err_msg)
|
||||
|
||||
@api.multi
|
||||
def _get_spread_period_duration(self):
|
||||
"""Converts the selected period_type to number of months."""
|
||||
self.ensure_one()
|
||||
@@ -308,7 +299,6 @@ class AccountSpread(models.Model):
|
||||
return 3
|
||||
return 1
|
||||
|
||||
@api.multi
|
||||
def _init_line_date(self, posted_line_ids):
|
||||
"""Calculates the initial spread date. This method
|
||||
is used by "def _compute_spread_board()" method.
|
||||
@@ -324,7 +314,6 @@ class AccountSpread(models.Model):
|
||||
spread_date = self.spread_date
|
||||
return spread_date
|
||||
|
||||
@api.multi
|
||||
def _next_line_date(self, month_day, date):
|
||||
"""Calculates the next spread date. This method
|
||||
is used by "def _compute_spread_board()" method.
|
||||
@@ -338,11 +327,10 @@ class AccountSpread(models.Model):
|
||||
date = date.replace(day=min(max_day_in_month, month_day))
|
||||
return date
|
||||
|
||||
@api.multi
|
||||
def _compute_spread_board(self):
|
||||
"""Creates the spread lines. This method is highly inspired
|
||||
from method compute_depreciation_board() present in standard
|
||||
"account_asset" module, developed by Odoo SA.
|
||||
Odoo 11.0 "account_asset" module, developed by Odoo SA.
|
||||
"""
|
||||
self.ensure_one()
|
||||
|
||||
@@ -391,19 +379,15 @@ class AccountSpread(models.Model):
|
||||
msg_body = _("Spread table '%s' created.") % invoice_type_selection
|
||||
self.message_post(body=msg_body)
|
||||
|
||||
@api.multi
|
||||
def _get_number_of_periods(self, month_day):
|
||||
"""Calculates the number of spread lines."""
|
||||
self.ensure_one()
|
||||
if month_day != 1:
|
||||
return self.period_number + 1
|
||||
return self.period_number
|
||||
return self.period_number + 1 if month_day != 1 else self.period_number
|
||||
|
||||
@staticmethod
|
||||
def _get_last_day_of_month(spread_date):
|
||||
return spread_date + relativedelta(day=31)
|
||||
|
||||
@api.multi
|
||||
def _compute_board_amount(self, sequence, amount, number_of_periods):
|
||||
"""Calculates the amount for the spread lines."""
|
||||
self.ensure_one()
|
||||
@@ -418,7 +402,6 @@ class AccountSpread(models.Model):
|
||||
amount = (amount_to_spread / period) / month_days * days
|
||||
return amount
|
||||
|
||||
@api.multi
|
||||
def compute_spread_board(self):
|
||||
"""Checks whether the spread lines should be calculated.
|
||||
In case checks pass, invoke "def _compute_spread_board()" method.
|
||||
@@ -426,7 +409,6 @@ class AccountSpread(models.Model):
|
||||
for spread in self.filtered(lambda s: s.total_amount):
|
||||
spread._compute_spread_board()
|
||||
|
||||
@api.multi
|
||||
def action_recalculate_spread(self):
|
||||
"""Recalculate spread"""
|
||||
self.ensure_one()
|
||||
@@ -435,37 +417,30 @@ class AccountSpread(models.Model):
|
||||
self.compute_spread_board()
|
||||
self.env["account.spread.line"]._create_entries()
|
||||
|
||||
@api.multi
|
||||
def action_undo_spread(self):
|
||||
"""Undo spreading: Remove all created moves,
|
||||
restore original account on move line"""
|
||||
"""Undo spreading: Remove all created moves"""
|
||||
self.ensure_one()
|
||||
self.mapped("line_ids").filtered("move_id").unlink_move()
|
||||
self.mapped("line_ids").unlink()
|
||||
|
||||
@api.multi
|
||||
def action_unlink_invoice_line(self):
|
||||
"""Unlink the invoice line from the spread board"""
|
||||
self.ensure_one()
|
||||
if self.invoice_id.state != "draft":
|
||||
raise UserError(
|
||||
_("Cannot unlink invoice lines if the invoice is validated")
|
||||
)
|
||||
msg = _("Cannot unlink invoice lines if the invoice is validated")
|
||||
raise UserError(msg)
|
||||
self._action_unlink_invoice_line()
|
||||
|
||||
@api.multi
|
||||
def _action_unlink_invoice_line(self):
|
||||
spread_mls = self.mapped("line_ids.move_id.line_ids")
|
||||
spread_mls.remove_move_reconcile()
|
||||
self.mapped("line_ids.move_id.line_ids").remove_move_reconcile()
|
||||
self._message_post_unlink_invoice_line()
|
||||
self.write({"invoice_line_ids": [(5, 0, 0)]})
|
||||
|
||||
def _message_post_unlink_invoice_line(self):
|
||||
for spread in self:
|
||||
invoice_id = spread.invoice_id.id
|
||||
inv_link = (
|
||||
"<a href=# data-oe-model=account.invoice "
|
||||
"data-oe-id=%d>%s</a>" % (invoice_id, _("Invoice"))
|
||||
"<a href=# data-oe-model=account.move "
|
||||
"data-oe-id=%d>%s</a>" % (spread.invoice_id.id, _("Invoice"))
|
||||
)
|
||||
msg_body = _("Unlinked invoice line '%s' (view %s).") % (
|
||||
spread.invoice_line_id.name,
|
||||
@@ -482,91 +457,61 @@ class AccountSpread(models.Model):
|
||||
)
|
||||
spread.invoice_id.message_post(body=msg_body)
|
||||
|
||||
@api.multi
|
||||
def unlink(self):
|
||||
if self.filtered(lambda s: s.invoice_line_id):
|
||||
raise UserError(
|
||||
_("Cannot delete spread(s) that are linked " "to an invoice line.")
|
||||
)
|
||||
err_msg = _("Cannot delete spread(s) that are linked to an invoice line.")
|
||||
raise UserError(err_msg)
|
||||
if self.mapped("line_ids.move_id").filtered(lambda m: m.state == "posted"):
|
||||
raise ValidationError(
|
||||
_("Cannot delete spread(s): there are " "posted Journal Entries.")
|
||||
)
|
||||
err_msg = _("Cannot delete spread(s): there are posted Journal Entries.")
|
||||
raise ValidationError(err_msg)
|
||||
return super().unlink()
|
||||
|
||||
@api.multi
|
||||
def reconcile_spread_moves(self):
|
||||
for spread in self:
|
||||
spread._reconcile_spread_moves()
|
||||
|
||||
@api.multi
|
||||
def _reconcile_spread_moves(self, created_moves=False):
|
||||
"""Reconcile spread moves if possible"""
|
||||
self.ensure_one()
|
||||
|
||||
if not self.invoice_id.number:
|
||||
return
|
||||
|
||||
spread_mls = self.line_ids.mapped("move_id.line_ids")
|
||||
if created_moves:
|
||||
spread_mls |= created_moves.mapped("line_ids")
|
||||
|
||||
spread_sign = True if self.total_amount >= 0.0 else False
|
||||
in_invoice_or_out_refund = ("in_invoice", "out_refund")
|
||||
account = self.invoice_line_id.account_id
|
||||
mls_to_reconcile = spread_mls.filtered(lambda l: l.account_id == account)
|
||||
|
||||
if self.invoice_type in in_invoice_or_out_refund and spread_sign:
|
||||
spread_mls = spread_mls.filtered(lambda x: x.credit != 0.0)
|
||||
elif self.invoice_type in in_invoice_or_out_refund:
|
||||
spread_mls = spread_mls.filtered(lambda x: x.debit != 0.0)
|
||||
elif spread_sign:
|
||||
spread_mls = spread_mls.filtered(lambda x: x.debit != 0.0)
|
||||
else:
|
||||
spread_mls = spread_mls.filtered(lambda x: x.credit != 0.0)
|
||||
|
||||
invoice_mls = self.invoice_id.move_id.mapped("line_ids")
|
||||
if self.invoice_id.type in in_invoice_or_out_refund and spread_sign:
|
||||
invoice_mls = invoice_mls.filtered(lambda x: x.debit != 0.0)
|
||||
elif self.invoice_id.type in in_invoice_or_out_refund:
|
||||
invoice_mls = invoice_mls.filtered(lambda x: x.credit != 0.0)
|
||||
elif spread_sign:
|
||||
invoice_mls = invoice_mls.filtered(lambda x: x.credit != 0.0)
|
||||
else:
|
||||
invoice_mls = invoice_mls.filtered(lambda x: x.debit != 0.0)
|
||||
|
||||
to_be_reconciled = self.env["account.move.line"]
|
||||
if len(invoice_mls) > 1:
|
||||
# Refine selection of move line.
|
||||
# The name is formatted the same way as it is done when creating
|
||||
# move lines in method "def invoice_line_move_line_get()" of
|
||||
# standard account module
|
||||
raw_name = self.invoice_line_id.name
|
||||
formatted_name = raw_name.split("\n")[0][:64]
|
||||
for move_line in invoice_mls:
|
||||
if move_line.name == formatted_name:
|
||||
to_be_reconciled |= move_line
|
||||
else:
|
||||
to_be_reconciled = invoice_mls
|
||||
|
||||
if len(to_be_reconciled) == 1:
|
||||
do_reconcile = spread_mls + to_be_reconciled
|
||||
if mls_to_reconcile:
|
||||
do_reconcile = mls_to_reconcile + self.invoice_line_id
|
||||
do_reconcile.remove_move_reconcile()
|
||||
do_reconcile._check_spread_reconcile_validity()
|
||||
do_reconcile.reconcile()
|
||||
|
||||
@api.multi
|
||||
def create_all_moves(self):
|
||||
for line in self.mapped("line_ids").filtered(lambda l: not l.move_id):
|
||||
line.create_move()
|
||||
|
||||
def _post_spread_moves(self, moves):
|
||||
self.ensure_one()
|
||||
if not moves:
|
||||
return
|
||||
ctx = dict(self.env.context, skip_unique_sequence_number=True)
|
||||
if self.company_id.force_move_auto_post or self.move_line_auto_post:
|
||||
moves.with_context(ctx).post()
|
||||
|
||||
@api.depends("debit_account_id.deprecated", "credit_account_id.deprecated")
|
||||
def _compute_deprecated_accounts(self):
|
||||
for spread in self:
|
||||
debit_deprecated = bool(spread.debit_account_id.deprecated)
|
||||
credit_deprecated = bool(spread.credit_account_id.deprecated)
|
||||
spread.is_debit_account_deprecated = debit_deprecated
|
||||
spread.is_credit_account_deprecated = credit_deprecated
|
||||
spread.is_debit_account_deprecated = spread.debit_account_id.deprecated
|
||||
spread.is_credit_account_deprecated = spread.credit_account_id.deprecated
|
||||
|
||||
@api.multi
|
||||
def open_reconcile_view(self):
|
||||
self.ensure_one()
|
||||
action_name = "account_spread_cost_revenue.action_account_moves_all_spread"
|
||||
[action] = self.env.ref(action_name).read()
|
||||
action["domain"] = [("id", "in", [])]
|
||||
spread_mls = self.line_ids.mapped("move_id.line_ids")
|
||||
return spread_mls.open_reconcile_view()
|
||||
spread_mls = spread_mls.filtered(lambda m: m.reconciled)
|
||||
if spread_mls:
|
||||
domain = [("id", "in", spread_mls.ids + [self.invoice_line_id.id])]
|
||||
action["domain"] = domain
|
||||
return action
|
||||
|
||||
Reference in New Issue
Block a user