diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/account/wizard/pos_box.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/account/wizard/pos_box.py')
| -rw-r--r-- | addons/account/wizard/pos_box.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/addons/account/wizard/pos_box.py b/addons/account/wizard/pos_box.py new file mode 100644 index 00000000..7c2931e0 --- /dev/null +++ b/addons/account/wizard/pos_box.py @@ -0,0 +1,54 @@ +from odoo import models, fields, api, _ +from odoo.exceptions import UserError + +class CashBox(models.TransientModel): + _register = False + + name = fields.Char(string='Reason', required=True) + # Attention, we don't set a domain, because there is a journal_type key + # in the context of the action + amount = fields.Float(string='Amount', digits=0, required=True) + + def run(self): + context = dict(self._context or {}) + active_model = context.get('active_model', False) + active_ids = context.get('active_ids', []) + + records = self.env[active_model].browse(active_ids) + + return self._run(records) + + def _run(self, records): + for box in self: + for record in records: + if not record.journal_id: + raise UserError(_("Please check that the field 'Journal' is set on the Bank Statement")) + if not record.journal_id.company_id.transfer_account_id: + raise UserError(_("Please check that the field 'Transfer Account' is set on the company.")) + box._create_bank_statement_line(record) + return {} + + def _create_bank_statement_line(self, record): + for box in self: + if record.state == 'confirm': + raise UserError(_("You cannot put/take money in/out for a bank statement which is closed.")) + values = box._calculate_values_for_statement_line(record) + account = record.journal_id.company_id.transfer_account_id + self.env['account.bank.statement.line'].with_context(counterpart_account_id=account.id).sudo().create(values) + + +class CashBoxOut(CashBox): + _name = 'cash.box.out' + _description = 'Cash Box Out' + + def _calculate_values_for_statement_line(self, record): + if not record.journal_id.company_id.transfer_account_id: + raise UserError(_("You have to define an 'Internal Transfer Account' in your cash register's journal.")) + amount = self.amount or 0.0 + return { + 'date': record.date, + 'statement_id': record.id, + 'journal_id': record.journal_id.id, + 'amount': amount, + 'payment_ref': self.name, + } |
