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", "name": "Account Cash Deposit",
"version": "14.0.1.1.0", "version": "16.0.1.0.0",
"category": "Accounting", "category": "Accounting",
"license": "AGPL-3", "license": "AGPL-3",
"summary": "Manage cash deposits and cash orders", "summary": "Manage cash deposits and cash orders",

View File

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

View File

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

View File

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

View File

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

View File

@ -17,7 +17,10 @@
attrs="{'invisible': [('active', '=', True)]}" attrs="{'invisible': [('active', '=', True)]}"
/> />
<group name="main"> <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="active" invisible="1" />
<field name="cash_type" /> <field name="cash_type" />
<field <field

View File

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