|
|
|
@ -60,6 +60,115 @@ class AccountCashDeposit(models.Model):
|
|
|
|
|
states={"draft": [("readonly", "=", False)]},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
Reconciliation
|
|
|
|
|
'''
|
|
|
|
|
is_matched = fields.Boolean(string="Is Matched With a Bank Statement", store=True,
|
|
|
|
|
compute='_compute_reconciliation')
|
|
|
|
|
is_reconcile = fields.Boolean(
|
|
|
|
|
compute="_compute_reconciliation", store=True, string="Reconciled"
|
|
|
|
|
)
|
|
|
|
|
reconciled_statement_line_ids = fields.Many2many(
|
|
|
|
|
comodel_name='account.bank.statement.line',
|
|
|
|
|
string="Reconciled Statement Lines",
|
|
|
|
|
compute='_compute_reconciliation',
|
|
|
|
|
help="Statements lines matched to this deposit",
|
|
|
|
|
)
|
|
|
|
|
reconciled_statement_lines_count = fields.Integer(
|
|
|
|
|
string="# Reconciled Statement Lines",
|
|
|
|
|
compute="_compute_reconciliation",
|
|
|
|
|
)
|
|
|
|
|
reconciled_statement_ids = fields.Many2many(
|
|
|
|
|
comodel_name='account.bank.statement',
|
|
|
|
|
string="Reconciled Statements",
|
|
|
|
|
compute='_compute_reconciliation',
|
|
|
|
|
help="Statements matched to this payment",
|
|
|
|
|
)
|
|
|
|
|
reconciled_statements_count = fields.Integer(
|
|
|
|
|
string="# Reconciled Statement",
|
|
|
|
|
compute="_compute_reconciliation",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@api.depends("move_id.line_ids.reconciled", "company_id")
|
|
|
|
|
def _compute_reconciliation(self):
|
|
|
|
|
for deposit in self:
|
|
|
|
|
match_counterpart = False
|
|
|
|
|
match_statement = False
|
|
|
|
|
reconciled_lines = self.env['account.move.line']
|
|
|
|
|
if deposit.move_id:
|
|
|
|
|
for line in deposit.move_id.line_ids:
|
|
|
|
|
if line.reconciled:
|
|
|
|
|
if line.account_id.id == deposit.move_id.journal_id.order_credit_account_id.id \
|
|
|
|
|
or deposit.move_id.journal_id.deposit_debit_account_id.id:
|
|
|
|
|
match_statement = True
|
|
|
|
|
elif line.account_id.id == deposit.partner_id.property_account_payable_id.id:
|
|
|
|
|
match_counterpart = True
|
|
|
|
|
elif line.account_id.id != self.company_id.transfer_account_id.id:
|
|
|
|
|
raise UserError("A line from the deposit %s is incorrect" % deposit.name)
|
|
|
|
|
|
|
|
|
|
if match_statement == True:
|
|
|
|
|
for partial in line.matched_credit_ids | line.matched_debit_ids:
|
|
|
|
|
reconciled_lines |= partial.debit_move_id | partial.credit_move_id
|
|
|
|
|
|
|
|
|
|
deposit.reconciled_statement_line_ids = [(6, 0, reconciled_lines.mapped('statement_line_id').ids)]
|
|
|
|
|
deposit.reconciled_statement_lines_count = len(deposit.reconciled_statement_line_ids)
|
|
|
|
|
deposit.is_matched = match_statement
|
|
|
|
|
deposit.is_reconcile = match_counterpart
|
|
|
|
|
statement_ids = {line.statement_id.id for line in reconciled_lines}
|
|
|
|
|
deposit.reconciled_statement_ids = [(6, 0, list(statement_ids))]
|
|
|
|
|
deposit.reconciled_statements_count = len(statement_ids)
|
|
|
|
|
|
|
|
|
|
def button_open_statement_lines(self):
|
|
|
|
|
''' Redirect the user to the statement line(s) reconciled to this payment.
|
|
|
|
|
:return: An action
|
|
|
|
|
'''
|
|
|
|
|
self.ensure_one()
|
|
|
|
|
|
|
|
|
|
action = {
|
|
|
|
|
'name': _("Matched Transactions"),
|
|
|
|
|
'type': 'ir.actions.act_window',
|
|
|
|
|
'res_model': 'account.bank.statement.line',
|
|
|
|
|
'context': {'create': False},
|
|
|
|
|
}
|
|
|
|
|
if len(self.reconciled_statement_line_ids) == 1:
|
|
|
|
|
action.update({
|
|
|
|
|
'view_mode': 'form',
|
|
|
|
|
'res_id': self.reconciled_statement_line_ids.id,
|
|
|
|
|
})
|
|
|
|
|
else:
|
|
|
|
|
action.update({
|
|
|
|
|
'view_mode': 'list,form',
|
|
|
|
|
'domain': [('id', 'in', self.reconciled_statement_line_ids.ids)],
|
|
|
|
|
})
|
|
|
|
|
return action
|
|
|
|
|
|
|
|
|
|
def button_open_statements(self):
|
|
|
|
|
self.ensure_one()
|
|
|
|
|
action = {
|
|
|
|
|
'name': _("Statements"),
|
|
|
|
|
'type': 'ir.actions.act_window',
|
|
|
|
|
'res_model': 'account.bank.statement',
|
|
|
|
|
'context': {'create': False, 'journal_type': 'cash'},
|
|
|
|
|
}
|
|
|
|
|
if len(self.reconciled_statement_ids) == 1:
|
|
|
|
|
action.update({
|
|
|
|
|
'views': [[self.env.ref('gn_cash.view_cash_statement_form').id, "form"]],
|
|
|
|
|
'res_id': self.reconciled_statement_ids.id,
|
|
|
|
|
})
|
|
|
|
|
else:
|
|
|
|
|
action.update({
|
|
|
|
|
'views': [[False, "list"], [self.env.ref('gn_cash.view_cash_statement_form').id, "form"]],
|
|
|
|
|
'domain': [('id', 'in', self.reconciled_statement_ids.ids)],
|
|
|
|
|
})
|
|
|
|
|
return action
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
End of fields and methods related to statements
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _prepare_account_move(self, vals):
|
|
|
|
|
move_vals = super()._prepare_account_move(vals)
|
|
|
|
|
if move_vals['line_ids']:
|
|
|
|
@ -67,15 +176,27 @@ class AccountCashDeposit(models.Model):
|
|
|
|
|
Inverse debit / credit and use suspense_account_id for further reconciliation with statement
|
|
|
|
|
'''
|
|
|
|
|
journal = self.env['account.journal'].browse(move_vals['journal_id'])
|
|
|
|
|
debit_account_id = journal.deposit_debit_account_id.id
|
|
|
|
|
credit_account_id = journal.order_credit_account_id.id
|
|
|
|
|
|
|
|
|
|
if not (debit_account_id or credit_account_id):
|
|
|
|
|
raise UserError("Default debit and credit account must be defined in journal settings")
|
|
|
|
|
|
|
|
|
|
for line_tuple in move_vals["line_ids"]:
|
|
|
|
|
if line_tuple[2]['account_id'] == self.company_id.transfer_account_id.id:
|
|
|
|
|
line_tuple[2]['account_id'] = journal.suspense_account_id.id
|
|
|
|
|
if line_tuple[2]['amount_currency'] > 0:
|
|
|
|
|
line_tuple[2]['account_id'] = debit_account_id
|
|
|
|
|
else:
|
|
|
|
|
line_tuple[2]['account_id'] = credit_account_id
|
|
|
|
|
if self.partner_id:
|
|
|
|
|
line_tuple[2]['partner_id'] = self.partner_id.id
|
|
|
|
|
else:
|
|
|
|
|
if self.partner_id:
|
|
|
|
|
line_tuple[2]['account_id'] = self.partner_id.property_account_payable_id.id
|
|
|
|
|
line_tuple[2]['partner_id'] = self.partner_id.id
|
|
|
|
|
else:
|
|
|
|
|
line_tuple[2]['account_id'] = self.company_id.transfer_account_id.id
|
|
|
|
|
|
|
|
|
|
return move_vals
|
|
|
|
|
|
|
|
|
|
def confirm_order_and_receive(self):
|
|
|
|
@ -95,7 +216,6 @@ class AccountCashDeposit(models.Model):
|
|
|
|
|
'qty': line['qty'],
|
|
|
|
|
'cash_unit_id': line['cash_unit_id'].id,
|
|
|
|
|
} for line in self.line_ids]
|
|
|
|
|
_logger.warning("lines are : %s" % lines)
|
|
|
|
|
counterpart_vals = {
|
|
|
|
|
'operation_type': 'order' if self.operation_type == 'deposit' else 'deposit',
|
|
|
|
|
'date': self.date,
|
|
|
|
@ -122,7 +242,6 @@ class AccountCashDeposit(models.Model):
|
|
|
|
|
super().validate(force_date=force_date)
|
|
|
|
|
counterpart_move = self.move_id
|
|
|
|
|
origin_move = self.env['account.move'].browse(self.env.context.get('is_counterpart_of')) if self.env.context.get('is_counterpart_of') else False
|
|
|
|
|
_logger.warning("context in validate deposit : %s" % dict(self.env.context))
|
|
|
|
|
if origin_move:
|
|
|
|
|
lines_to_reconcile = [line for line in (counterpart_move.line_ids + origin_move.line_ids) if line.account_id.id == self.company_id.transfer_account_id.id]
|
|
|
|
|
if len(lines_to_reconcile) == 2:
|
|
|
|
@ -144,7 +263,6 @@ class AccountCashOrderReception(models.TransientModel):
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
|
super().run()
|
|
|
|
|
_logger.warning("context in run: %s " % self.env.context)
|
|
|
|
|
context = dict(self.env.context)
|
|
|
|
|
if not self.order_id.partner_id and not self.order_id.is_reconcile:
|
|
|
|
|
return {
|
|
|
|
|