mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[WIP] automatic reconcile statement line cash and linked folio payments
This commit is contained in:
@@ -14,3 +14,44 @@ class AccountBankStatement(models.Model):
|
|||||||
string="Company",
|
string="Company",
|
||||||
help="The company for Account Bank Statement",
|
help="The company for Account Bank Statement",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def button_post(self):
|
||||||
|
"""
|
||||||
|
Override the default method to add autoreconcile payments and statement lines
|
||||||
|
"""
|
||||||
|
lines_of_moves_to_post = self.line_ids.filtered(
|
||||||
|
lambda line: line.move_id.state != "posted"
|
||||||
|
)
|
||||||
|
super(AccountBankStatement, self).button_post()
|
||||||
|
for line in lines_of_moves_to_post:
|
||||||
|
folio_ids = line.folio_ids.ids
|
||||||
|
if folio_ids:
|
||||||
|
to_reconcile_ids = self.env["account.move.line"].search(
|
||||||
|
[
|
||||||
|
("move_id.folio_ids", "in", folio_ids),
|
||||||
|
("reconciled", "=", False),
|
||||||
|
"|",
|
||||||
|
(
|
||||||
|
"account_id",
|
||||||
|
"=",
|
||||||
|
self.journal_id.payment_debit_account_id.id,
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"account_id",
|
||||||
|
"=",
|
||||||
|
self.journal_id.payment_credit_account_id.id,
|
||||||
|
),
|
||||||
|
("journal_id", "=", self.journal_id.id),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
if to_reconcile_ids:
|
||||||
|
statement_move_line = line.move_id.line_ids.filtered(
|
||||||
|
lambda line: line.account_id.reconcile
|
||||||
|
)
|
||||||
|
payment_line = self.env["account.move.line"].browse(
|
||||||
|
to_reconcile_ids.ids
|
||||||
|
)[0]
|
||||||
|
if payment_line and statement_move_line:
|
||||||
|
statement_move_line.account_id = payment_line.account_id
|
||||||
|
lines_to_reconcile = payment_line + statement_move_line
|
||||||
|
lines_to_reconcile.reconcile()
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class AccountMove(models.Model):
|
|||||||
column1="account_move_id",
|
column1="account_move_id",
|
||||||
column2="folio_ids_id",
|
column2="folio_ids_id",
|
||||||
store=True,
|
store=True,
|
||||||
|
readonly=False,
|
||||||
)
|
)
|
||||||
pms_property_id = fields.Many2one(
|
pms_property_id = fields.Many2one(
|
||||||
string="Property",
|
string="Property",
|
||||||
@@ -40,14 +41,11 @@ class AccountMove(models.Model):
|
|||||||
else:
|
else:
|
||||||
move.pms_property_id = False
|
move.pms_property_id = False
|
||||||
|
|
||||||
@api.depends("invoice_line_ids")
|
@api.depends("line_ids", "line_ids.folio_ids")
|
||||||
def _compute_folio_origin(self):
|
def _compute_folio_origin(self):
|
||||||
for move in self:
|
for move in self:
|
||||||
move.folio_ids = False
|
move.folio_ids = False
|
||||||
if move.invoice_line_ids:
|
move.folio_ids = move.mapped("line_ids.folio_ids.id")
|
||||||
move.folio_ids = move.mapped("invoice_line_ids.folio_ids.id")
|
|
||||||
elif move.line_ids and move.line_ids.sale_line_ids:
|
|
||||||
move.folio_ids = move.mapped("line_ids.sale_line_ids.folio_id.id")
|
|
||||||
|
|
||||||
def _compute_payments_widget_to_reconcile_info(self):
|
def _compute_payments_widget_to_reconcile_info(self):
|
||||||
for move in self:
|
for move in self:
|
||||||
|
|||||||
@@ -19,8 +19,10 @@ class AccountMoveLine(models.Model):
|
|||||||
column2="sale_line_id",
|
column2="sale_line_id",
|
||||||
)
|
)
|
||||||
folio_ids = fields.Many2many(
|
folio_ids = fields.Many2many(
|
||||||
related="payment_id.folio_ids",
|
comodel_name="pms.folio",
|
||||||
string="Folios",
|
string="Folios",
|
||||||
|
compute="_compute_folio_ids",
|
||||||
|
store=True,
|
||||||
)
|
)
|
||||||
name_changed_by_user = fields.Boolean(
|
name_changed_by_user = fields.Boolean(
|
||||||
string="Custom label",
|
string="Custom label",
|
||||||
@@ -51,6 +53,23 @@ class AccountMoveLine(models.Model):
|
|||||||
readonly=False,
|
readonly=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@api.depends(
|
||||||
|
"folio_line_ids",
|
||||||
|
"payment_id",
|
||||||
|
"payment_id.folio_ids",
|
||||||
|
"statement_line_id",
|
||||||
|
"statement_line_id.folio_ids",
|
||||||
|
)
|
||||||
|
def _compute_folio_ids(self):
|
||||||
|
if self.folio_line_ids:
|
||||||
|
self.folio_ids = self.folio_line_ids.mapped("folio_id")
|
||||||
|
elif self.payment_id:
|
||||||
|
self.folio_ids = self.payment_id.folio_ids
|
||||||
|
elif self.statement_line_id:
|
||||||
|
self.folio_ids = self.statement_line_id.folio_ids
|
||||||
|
else:
|
||||||
|
self.folio_ids = False
|
||||||
|
|
||||||
@api.depends("quantity")
|
@api.depends("quantity")
|
||||||
def _compute_name(self):
|
def _compute_name(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
|
|||||||
Reference in New Issue
Block a user