Skip to content

Commit 4199a68

Browse files
committed
[FIX] cancellation on voucher and bank receopt
1 parent 1f69127 commit 4199a68

File tree

8 files changed

+33
-18
lines changed

8 files changed

+33
-18
lines changed

account_bank_receipt/models/account.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ class AccountJournal(models.Model):
1414
)
1515

1616

17+
class AccountMoveLine(models.Model):
18+
_inherit = "account.move.line"
19+
20+
bank_receipt_id = fields.Many2one(
21+
'account.bank.receipt', string='Bank Receipt', copy=False)
22+
23+
1724
class AccountMove(models.Model):
1825
_inherit = 'account.move'
1926

@@ -29,10 +36,12 @@ class AccountMove(models.Model):
2936
@api.depends('line_id.bank_receipt_id')
3037
def _compute_bank_receipt(self):
3138
for move in self:
32-
bank_receipt_line = move.line_id.filtered('bank_receipt_id')
33-
move.bank_receipt_id = bank_receipt_line.bank_receipt_id
34-
if move.bank_receipt_id:
39+
if move.bank_receipt_id: # Not yet assigned
3540
break
41+
move_lines = move.line_id.filtered('bank_receipt_id')
42+
bank_receipts = move_lines.mapped('bank_receipt_id')
43+
if bank_receipts:
44+
move.bank_receipt_id = bank_receipts[0]
3645

3746
@api.multi
3847
def create_bank_receipt(self, receipt_date):

account_bank_receipt/models/account_bank_receipt.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class AccountBankReceipt(models.Model):
1616
size=64,
1717
readonly=True,
1818
default='/',
19+
copy=False,
1920
)
2021
bank_intransit_ids = fields.One2many(
2122
'account.move.line',
@@ -349,10 +350,3 @@ def onchange_journal_id(self):
349350
self.currency_id = self.journal_id.currency
350351
else:
351352
self.currency_id = self.journal_id.company_id.currency_id
352-
353-
354-
class AccountMoveLine(models.Model):
355-
_inherit = "account.move.line"
356-
357-
bank_receipt_id = fields.Many2one(
358-
'account.bank.receipt', string='Bank Receipt', copy=False)

account_bank_receipt/views/account_bank_receipt_view.xml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<field name="account_id" readonly="1"/>
1717
<field name="debit" sum="Total Debit" readonly="1"/>
1818
<field name="credit" sum="Total Credit" readonly="1"/>
19+
<field name="reconcile_id" readonly="1"/>
1920
</tree>
2021
</field>
2122
</record>

account_bank_receipt/wizard/voucher_create_bank_receipt_wizard.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ def voucher_create_bank_receipt(self):
1717
active_model = self._context.get('active_model')
1818
active_ids = self._context.get('active_ids')
1919
moves = self.env[active_model].browse(active_ids).mapped('move_id')
20-
moves.create_bank_receipt(self.receipt_date)
21-
return
20+
bank_receipt_id = moves.create_bank_receipt(self.receipt_date)
21+
action = self.env.ref('account_bank_receipt.action_bank_receipt_tree')
22+
result = action.read()[0]
23+
result['domain'] = [('id', '=', bank_receipt_id)]
24+
return result

account_bank_receipt_cancel_reason/wizard/cancel_reason.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def confirm_cancel(self):
2222
assert len(bank_receipt_ids) == 1, "Only 1 sale ID expected"
2323
BankReceipt = self.env['account.bank.receipt']
2424
bank_receipt = BankReceipt.browse(bank_receipt_ids[0])
25-
bank_receipt.write({'cancel_reason_txt': self.cancel_reason_txt,
26-
'state': 'cancel',
27-
})
25+
bank_receipt.write({'cancel_reason_txt': self.cancel_reason_txt})
26+
bank_receipt.cancel_bank_receipt()
2827
return act_close

account_bank_receipt_deduction/models/account_bank_receipt.py

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class AccountBankReceipt(models.Model):
6767
manual_total_amount = fields.Float(
6868
string="Total Amount",
6969
readonly=True,
70+
default=0.0,
7071
states={'draft': [('readonly', False)]},
7172
required=True,
7273
)

account_cancel_reversal/models/account_bank_receipt.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def _cancel_move(self):
2424
'ref': move.ref})
2525
rev_move._switch_dr_cr()
2626
self.cancel_move_id = rev_move
27-
# As accounto n both DR and CR are balance sheet item, do one by one
27+
# As account both DR and CR are balance sheet item, do one by one
2828
accounts = move.line_id.mapped('account_id')
2929
for account in accounts:
3030
self.env['account.move'].\

account_cancel_reversal/models/account_voucher.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@ def voucher_move_cancel_hook(self, voucher):
2121
'ref': move.ref})
2222
rev_move._switch_dr_cr()
2323
voucher.cancel_move_id = rev_move
24-
self.env['account.move'].\
25-
_reconcile_voided_entry([move.id, rev_move.id])
24+
# Delete reconcile, and receconcile with reverse entry
25+
move.line_id.filtered('reconcile_id').reconcile_id.unlink()
26+
accounts = move.line_id.mapped('account_id')
27+
for account in accounts:
28+
self.env['account.move'].\
29+
_reconcile_voided_entry_by_account([move.id, rev_move.id],
30+
account.id)
31+
32+
# self.env['account.move'].\
33+
# _reconcile_voided_entry([move.id, rev_move.id])
2634
return
2735

2836
@api.model

0 commit comments

Comments
 (0)