2
0

[MIG] account_cash_deposit to v16

This commit is contained in:
Alexis de Lattre 2022-12-12 21:12:46 +01:00
parent 6c68352033
commit 65dc46c91e
9 changed files with 85 additions and 56 deletions

View File

@ -4,7 +4,7 @@
{
"name": "Account Cash Deposit",
"version": "14.0.1.1.0",
"version": "16.0.1.0.0",
"category": "Accounting",
"license": "AGPL-3",
"summary": "Manage cash deposits and cash orders",

View File

@ -22,7 +22,6 @@ class AccountCashDeposit(models.Model):
("order", "Cash Order"),
],
required=True,
string="Operation Type",
readonly=True,
)
line_ids = fields.One2many(
@ -38,7 +37,6 @@ class AccountCashDeposit(models.Model):
states={"draft": [("readonly", "=", False)]},
)
date = fields.Date(
string="Date",
states={"done": [("readonly", "=", True)]},
tracking=True,
copy=False,
@ -56,7 +54,6 @@ class AccountCashDeposit(models.Model):
)
currency_id = fields.Many2one(
"res.currency",
string="Currency",
required=True,
tracking=True,
readonly=True,
@ -92,7 +89,6 @@ class AccountCashDeposit(models.Model):
)
company_id = fields.Many2one(
"res.company",
string="Company",
required=True,
readonly=True,
states={"draft": [("readonly", "=", False)]},
@ -110,7 +106,7 @@ class AccountCashDeposit(models.Model):
)
total_amount = fields.Monetary(
compute="_compute_total_amount",
string="Total Amount",
precompute=True,
store=True,
currency_field="currency_id",
tracking=True,
@ -195,16 +191,15 @@ class AccountCashDeposit(models.Model):
res["line_ids"] = [(0, 0, {"cash_unit_id": cu.id}) for cu in cash_units]
return res
@api.depends("line_ids.subtotal")
@api.depends("line_ids.subtotal", "coin_amount")
def _compute_total_amount(self):
rg_res = self.env["account.cash.deposit.line"].read_group(
[("parent_id", "in", self.ids)],
["parent_id", "subtotal"],
["parent_id"],
)
mapped_data = {x["parent_id"][0]: x["subtotal"] for x in rg_res}
# With precompute=True, we can't use read_group() any more,
# because it won't work with NewID
for rec in self:
rec.total_amount = mapped_data.get(rec.id, 0) + rec.coin_amount
total_amount = rec.coin_amount
for line in rec.line_ids:
total_amount += line.subtotal
rec.total_amount = total_amount
@api.depends("move_id.line_ids.reconciled", "company_id")
def _compute_is_reconcile(self):
@ -231,15 +226,20 @@ class AccountCashDeposit(models.Model):
def backtodraft(self):
for rec in self:
if rec.move_id:
if rec.is_reconcile:
raise UserError(
_("%s has already been credited/debited on the bank account.")
% rec.display_name
)
move = rec.move_id
# It will raise here if journal_id.update_posted = False
if move.state == "posted":
move.button_draft()
move.unlink()
move.with_context(force_delete=True).unlink()
rec.write({"state": "draft"})
@api.model
def create(self, vals):
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if "company_id" in vals:
self = self.with_company(vals["company_id"])
if vals.get("name", "/") == "/":
@ -254,7 +254,7 @@ class AccountCashDeposit(models.Model):
vals["name"] = self.env["ir.sequence"].next_by_code(
"account.cash.deposit"
)
return super().create(vals)
return super().create(vals_list)
def name_get(self):
res = []
@ -381,7 +381,7 @@ class AccountCashDeposit(models.Model):
def get_report(self):
report = self.env.ref("account_cash_deposit.report_account_cash_deposit")
action = report.with_context({"discard_logo_check": True}).report_action(self)
action = report.with_context(discard_logo_check=True).report_action(self)
return action
@ -396,7 +396,7 @@ class AccountCashDepositLine(models.Model):
"cash.unit", required=True, domain="[('currency_id', '=', currency_id)]"
)
tree_order = fields.Float(related="cash_unit_id.tree_order", store=True)
subtotal = fields.Monetary(compute="_compute_subtotal", store=True)
subtotal = fields.Monetary(compute="_compute_subtotal", store=True, precompute=True)
currency_id = fields.Many2one(related="parent_id.currency_id", store=True)
_sql_constraints = [

View File

@ -2,10 +2,14 @@
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo.tools.misc import format_amount
logger = logging.getLogger(__name__)
class CashUnit(models.Model):
_name = "cash.unit"
@ -127,8 +131,8 @@ class CashUnit(models.Model):
value = False
try:
value = float(name)
except Exception:
pass
except ValueError:
logger.debug("name %s is not a float. Make pylint happy.", name)
if value:
recs = self.search([("value", "=", value)] + args, limit=limit)
if recs:
@ -139,8 +143,8 @@ class CashUnit(models.Model):
if decimal_sep and decimal_sep != ".":
try:
value = float(name.replace(decimal_sep, ".", 1))
except Exception:
pass
except ValueError:
logger.debug("name %s is not a float. Make pylint happy.", name)
if value:
recs = self.search([("value", "=", value)] + args, limit=limit)
if recs:

View File

@ -56,8 +56,8 @@
<thead>
<tr>
<th>Cash Unit</th>
<th class="text-right">Quantity</th>
<th class="text-right">Subtotal</th>
<th class="text-end">Quantity</th>
<th class="text-end">Subtotal</th>
</tr>
</thead>
<tbody>
@ -68,27 +68,30 @@
t-field="line.cash_unit_id.display_name"
/>
</td>
<td class="text-right">
<td class="text-end">
<span t-field="line.qty" />
</td>
<td class="text-right">
<span
t-field="line.subtotal"
t-field-options='{"widget": "monetary", "display_currency": "o.currency_id"}'
/>
<td class="text-end">
<span t-field="line.subtotal" />
</td>
</tr>
</t>
<tr class="border-black o_total" t-if="o.coin_amount">
<td />
<td class="text-end">
<strong>Loose Coins:</strong>
</td>
<td class="text-end">
<span t-field="o.coin_amount" />
</td>
</tr>
<tr class="border-black o_total">
<td />
<td class="text-right">
<td class="text-end">
<strong>Total:</strong>
</td>
<td class="text-right">
<span
t-field="o.total_amount"
t-field-options='{"widget": "monetary", "display_currency": "o.currency_id"}'
/>
<td class="text-end">
<span t-field="o.total_amount" />
</td>
</tr>
</tbody>

View File

@ -66,6 +66,7 @@
name="currency_id"
groups="base.group_multi_currency"
/>
<field name="currency_id" invisible="1" />
<field name="cash_journal_id" />
<field name="bank_journal_id" />
<field
@ -80,6 +81,7 @@
name="company_id"
groups="base.group_multi_company"
/>
<field name="company_id" invisible="1" />
<field name="move_id" />
</group>
</group>
@ -87,6 +89,7 @@
<field
name="line_ids"
nolabel="1"
colspan="2"
context="{'default_currency_id': currency_id}"
>
<tree editable="bottom">
@ -129,7 +132,11 @@
optional="hide"
/>
<field name="is_reconcile" optional="show" />
<field name="company_id" groups="base.group_multi_company" />
<field
name="company_id"
groups="base.group_multi_company"
optional="show"
/>
<field
name="state"
widget="badge"
@ -184,6 +191,11 @@
string="Currency"
context="{'group_by': 'currency_id'}"
/>
<filter
name="state_groupby"
string="State"
context="{'group_by': 'state'}"
/>
</group>
</search>
</field>

View File

@ -17,7 +17,10 @@
attrs="{'invisible': [('active', '=', True)]}"
/>
<group name="main">
<field name="currency_id" />
<field
name="currency_id"
invisible="not context.get('cash_unit_main_view')"
/>
<field name="active" invisible="1" />
<field name="cash_type" />
<field

View File

@ -12,7 +12,7 @@
<field name="arch" type="xml">
<sheet position="inside">
<group name="cash_units" string="Cash Units">
<field name="cash_unit_ids" nolabel="1" />
<field name="cash_unit_ids" nolabel="1" colspan="2" />
</group>
</sheet>
</field>

View File

@ -0,0 +1 @@
../../../../account_cash_deposit

View File

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)