[IMP] account, point_of_sale: take money from cash journal

When you have a cash journal, you have the opportunity to use a wizard
to easily create the statement. There are two wizards, one to add money
in the journal, and one to remove money.

To simplify the code and remove some duplication, we are now using only
one wizard, that will allow to add and/or remove money from the cash
journal.

TASK-ID: 1934784
This commit is contained in:
Robin Heinz
2019-07-23 07:41:20 +00:00
committed by Pierre Masereel
parent 733fb360d2
commit 2eb1cde534
5 changed files with 8 additions and 81 deletions
+2 -22
View File
@@ -5,7 +5,7 @@ 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
# 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)
@@ -36,26 +36,6 @@ class CashBox(models.TransientModel):
record.write({'line_ids': [(0, False, values)]})
class CashBoxIn(CashBox):
_name = 'cash.box.in'
_description = 'Cash Box In'
ref = fields.Char('Reference')
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."))
return {
'date': record.date,
'statement_id': record.id,
'journal_id': record.journal_id.id,
'amount': self.amount or 0.0,
'account_id': record.journal_id.company_id.transfer_account_id.id,
'ref': '%s' % (self.ref or ''),
'name': self.name,
}
class CashBoxOut(CashBox):
_name = 'cash.box.out'
_description = 'Cash Box Out'
@@ -68,7 +48,7 @@ class CashBoxOut(CashBox):
'date': record.date,
'statement_id': record.id,
'journal_id': record.journal_id.id,
'amount': -amount if amount > 0.0 else amount,
'amount': amount,
'account_id': record.journal_id.company_id.transfer_account_id.id,
'name': self.name,
}
+4 -30
View File
@@ -1,45 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<record model="ir.ui.view" id="cash_box_in_form">
<field name="name">cash_box_in</field>
<field name="model">cash.box.in</field>
<field name="arch" type="xml">
<form string="Put Money In">
<separator string="Fill in this form if you put money in the cash register:" colspan="4" />
<group>
<field name="name" class="oe_inline"/>
<field name="amount" class="oe_inline"/>
</group>
<footer>
<button name="run" string="Put Money In" type="object" class="btn-primary"/>
<button special="cancel" string="Cancel" class="btn-secondary"/>
</footer>
</form>
</field>
</record>
<act_window
name="Put Money In"
res_model="cash.box.in"
binding_model="account.bank.statement"
view_mode="form"
target="new"
id="action_cash_box_in" />
<record model="ir.ui.view" id="cash_box_out_form">
<field name="name">cash_box_out</field>
<field name="model">cash.box.out</field>
<field name="arch" type="xml">
<form string="Take Money Out">
<separator string="Describe why you take money from the cash register:"/>
<form string="Take Money In/Out">
<separator string="Describe why you put/take money from the cash register:"/>
<group>
<field name="name" class="oe_inline"/>
<field name="amount" class="oe_inline"/>
</group>
<footer>
<button name="run" string="Take Money Out" type="object" class="btn-primary"/>
<button name="run" string="Take Money In/Out" type="object" class="btn-primary"/>
<button class="btn-secondary" special="cancel" string="Cancel" />
</footer>
</form>
@@ -47,7 +21,7 @@
</record>
<act_window
name="Take Money Out"
name="Take Money In/Out"
res_model="cash.box.out"
binding_model="account.bank.statement"
view_mode="form"
@@ -25,20 +25,12 @@
<sheet>
<field name="cash_register_id" invisible="1"/>
<div class="oe_button_box" name="button_box">
<button class="oe_stat_button" name="%(action_pos_box_in)d"
type="action" icon="fa-level-down"
attrs="{'invisible': ['|', ('cash_control', '=', False), ('state', 'not in', ['opened', 'closing_control'])]}">
<div class="o_field_widget o_stat_info">
<span class="o_stat_text">Put</span>
<span class="o_stat_text">Money In</span>
</div>
</button>
<button class="oe_stat_button" name="%(action_pos_box_out)d"
type="action" icon="fa-level-up"
attrs="{'invisible': ['|', ('cash_control', '=', False), ('state', 'not in', ['opened', 'closing_control'])]}">
<div class="o_field_widget o_stat_info">
<span class="o_stat_text">Take</span>
<span class="o_stat_text">Money Out</span>
<span class="o_stat_text">Money In/Out</span>
</div>
</button>
<button name="open_cashbox"
-12
View File
@@ -23,18 +23,6 @@ class PosBox(CashBox):
return super(PosBox, self).run()
class PosBoxIn(PosBox):
_inherit = 'cash.box.in'
def _calculate_values_for_statement_line(self, record):
values = super(PosBoxIn, self)._calculate_values_for_statement_line(record=record)
active_model = self.env.context.get('active_model', False)
active_ids = self.env.context.get('active_ids', [])
if active_model == 'pos.session' and active_ids:
values['ref'] = self.env[active_model].browse(active_ids)[0].name
return values
class PosBoxOut(PosBox):
_inherit = 'cash.box.out'
+1 -8
View File
@@ -1,15 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<act_window
id="action_pos_box_in"
name="Put Money In"
res_model="cash.box.in"
view_mode="form"
target="new"/>
<act_window
id="action_pos_box_out"
name="Take Money Out"
name="Take Money In/Out"
res_model="cash.box.out"
view_mode="form"
target="new"/>