Skip to content

Commit

Permalink
[IMP] l10n_it_asset_management: Recharge asset
Browse files Browse the repository at this point in the history
  • Loading branch information
SirAionTech committed Oct 9, 2024
1 parent 323c128 commit 0751cd8
Show file tree
Hide file tree
Showing 15 changed files with 503 additions and 32 deletions.
13 changes: 11 additions & 2 deletions l10n_it_asset_management/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ Depreciations can be generated by using the related wizard found in
Assets -> Assets Management -> Generate Depreciations, or by triggering
the same wizard from a single asset form view.

When an asset is returned, it is possible to recharge its purchase and
fund amounts choosing "Partial Recharge" in the "Link to Asset" wizard
of the credit note. The wizard will allow to link to the credit note
only the assets of the refunded invoice.

**Italiano**

È possibile creare e gestire cespiti dalla sezione contabilità di Odoo.
Expand All @@ -63,6 +68,11 @@ contabili. Gli ammortamenti possono essere generati utilizzando
l'apposito wizard in Cespiti -> Gestione Cestpiti -> Genera
Ammortamenti, o aprendo quello stesso wizard dalla scheda del cespite.

Quando un cespite viene restituito, è possibile ricaricare gli importi
di acquisto e di fondo scegliendo "Ricarica parziale" nella procedura
"Collega a cespite" della nota di credito. La procedura consentirà di
collegare alla nota di credito solo i cespiti della fattura rimborsata.

Bug Tracker
===========

Expand Down Expand Up @@ -99,8 +109,7 @@ Contributors
- Nextev Srl <[email protected]>

Base icon made by `surang <https://www.flaticon.com/authors/surang>`__
from
[`www.flaticon.com](https://www.flaticon.com/) <http://www.flaticon.com](https://www.flaticon.com/)>`__.
from `www.flaticon.com <http://www.flaticon.com>`__.

Maintainers
-----------
Expand Down
1 change: 1 addition & 0 deletions l10n_it_asset_management/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def open_wizard_manage_asset(self):
{
"default_company_id": self.company_id.id,
"default_dismiss_date": self.invoice_date or self.invoice_date_due,
"default_recharge_date": self.invoice_date or self.invoice_date_due,
"default_move_ids": [Command.set(self.ids)],
"default_move_line_ids": [Command.set(lines.ids)],
"default_purchase_date": self.invoice_date or self.invoice_date_due,
Expand Down
1 change: 1 addition & 0 deletions l10n_it_asset_management/models/asset_accounting_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class AssetAccountingInfo(models.Model):
relation_type = fields.Selection(
[
("create", "Asset Creation"),
("partial_recharge", "Partial Recharge"),
("update", "Asset Update"),
("partial_dismiss", "Asset Partial Dismissal"),
("dismiss", "Asset Dismissal"),
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_asset_management/models/asset_depreciation.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def _compute_last_depreciation_date(self):
for dep in self:
dep_lines = dep.line_ids.filtered(
lambda line: line.move_type == "depreciated"
and not line.partial_dismissal
and not (line.partial_dismissal or line.partial_recharge)
)
if dep_lines:
dep.last_depreciation_date = max(dep_lines.mapped("date"))
Expand Down
20 changes: 15 additions & 5 deletions l10n_it_asset_management/models/asset_depreciation_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class AssetDepreciationLine(models.Model):
)

partial_dismissal = fields.Boolean()
partial_recharge = fields.Boolean()

percentage = fields.Float(string="%")

Expand Down Expand Up @@ -265,9 +266,8 @@ def get_update_move_types(self):
def is_depreciation_nr_required(self):
"""Defines if a line requires to be numbered"""
self.ensure_one()
return (
self.move_type in self.get_numbered_move_types()
and not self.partial_dismissal
return self.move_type in self.get_numbered_move_types() and not (
self.partial_dismissal or self.partial_recharge
)

def make_name(self):
Expand Down Expand Up @@ -398,15 +398,22 @@ def get_depreciated_account_move_line_vals(self):
self.ensure_one()

# Asset depreciation
if not self.partial_dismissal:
if not (self.partial_dismissal or self.partial_recharge):
credit_account_id = self.asset_id.category_id.fund_account_id.id
debit_account_id = self.asset_id.category_id.depreciation_account_id.id

# Asset partial dismissal
else:
# Asset partial dismissal
debit_account_id = self.asset_id.category_id.fund_account_id.id
credit_account_id = self.asset_id.category_id.asset_account_id.id

# Asset partial recharge
if self.partial_recharge:
credit_account_id, debit_account_id = (
debit_account_id,
credit_account_id,
)

amt = abs(self.amount)
credit_line_vals = {
"account_id": credit_account_id,
Expand Down Expand Up @@ -499,3 +506,6 @@ def post_partial_dismiss_asset(self):
)
if to_create_move:
to_create_move.generate_account_move()

def post_partial_recharge_asset(self):
return self.post_partial_dismiss_asset()
6 changes: 6 additions & 0 deletions l10n_it_asset_management/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Depreciations can be generated by using the related wizard found in
Assets -\> Assets Management -\> Generate Depreciations, or by
triggering the same wizard from a single asset form view.

When an asset is returned, it is possible to recharge its purchase and fund amounts choosing "Partial Recharge" in the "Link to Asset" wizard of the credit note.
The wizard will allow to link to the credit note only the assets of the refunded invoice.

**Italiano**

È possibile creare e gestire cespiti dalla sezione contabilità di Odoo.
Expand All @@ -22,3 +25,6 @@ I cespiti possono essere creati manualmente o da fatture e registrazioni
contabili. Gli ammortamenti possono essere generati utilizzando
l'apposito wizard in Cespiti -\> Gestione Cestpiti -\> Genera
Ammortamenti, o aprendo quello stesso wizard dalla scheda del cespite.

Quando un cespite viene restituito, è possibile ricaricare gli importi di acquisto e di fondo scegliendo "Ricarica parziale" nella procedura "Collega a cespite" della nota di credito.
La procedura consentirà di collegare alla nota di credito solo i cespiti della fattura rimborsata.
4 changes: 2 additions & 2 deletions l10n_it_asset_management/report/asset_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ def get_report_dep_line_year_data(self):
line.amount
for line in self.dep_line_ids.filtered(
lambda line: line.move_type == "depreciated"
and not line.partial_dismissal
and not (line.partial_dismissal or line.partial_recharge)
)
]
)
Expand All @@ -737,7 +737,7 @@ def get_report_dep_line_year_data(self):
line.amount
for line in self.dep_line_ids.filtered(
lambda line: line.move_type == "depreciated"
and line.partial_dismissal
and (line.partial_dismissal or line.partial_recharge)
)
]
)
Expand Down
8 changes: 5 additions & 3 deletions l10n_it_asset_management/report/asset_previsional.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ def generate_structure(self):
if fyear.date_to >= dep.date_start:
prev = not lines or not any(
line.move_type == "depreciated"
and not line.partial_dismissal
and not (
line.partial_dismissal or line.partial_recharge
)
for line in lines
)
sequence += 1
Expand Down Expand Up @@ -797,7 +799,7 @@ def get_report_dep_line_year_data(self):
line.amount
for line in self.dep_line_ids.filtered(
lambda line: line.move_type == "depreciated"
and not line.partial_dismissal
and not (line.partial_dismissal or line.partial_recharge)
)
]
)
Expand All @@ -806,7 +808,7 @@ def get_report_dep_line_year_data(self):
line.amount
for line in self.dep_line_ids.filtered(
lambda line: line.move_type == "depreciated"
and line.partial_dismissal
and (line.partial_dismissal or line.partial_recharge)
)
]
)
Expand Down
11 changes: 9 additions & 2 deletions l10n_it_asset_management/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
Depreciations can be generated by using the related wizard found in
Assets -&gt; Assets Management -&gt; Generate Depreciations, or by triggering
the same wizard from a single asset form view.</p>
<p>When an asset is returned, it is possible to recharge its purchase and
fund amounts choosing “Partial Recharge” in the “Link to Asset” wizard
of the credit note. The wizard will allow to link to the credit note
only the assets of the refunded invoice.</p>
<p><strong>Italiano</strong></p>
<p>È possibile creare e gestire cespiti dalla sezione contabilità di Odoo.</p>
<p>La configurazione dei cespiti dev’essere fatta andando in Cespiti -&gt;
Expand All @@ -403,6 +407,10 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
contabili. Gli ammortamenti possono essere generati utilizzando
l’apposito wizard in Cespiti -&gt; Gestione Cestpiti -&gt; Genera
Ammortamenti, o aprendo quello stesso wizard dalla scheda del cespite.</p>
<p>Quando un cespite viene restituito, è possibile ricaricare gli importi
di acquisto e di fondo scegliendo “Ricarica parziale” nella procedura
“Collega a cespite” della nota di credito. La procedura consentirà di
collegare alla nota di credito solo i cespiti della fattura rimborsata.</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
Expand Down Expand Up @@ -438,8 +446,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Nextev Srl &lt;<a class="reference external" href="mailto:odoo&#64;nextev.it">odoo&#64;nextev.it</a>&gt;</li>
</ul>
<p>Base icon made by <a class="reference external" href="https://www.flaticon.com/authors/surang">surang</a>
from
[<a class="reference external" href="http://www.flaticon.com](https://www.flaticon.com/)">www.flaticon.com](https://www.flaticon.com/)</a>.</p>
from <a class="reference external" href="http://www.flaticon.com">www.flaticon.com</a>.</p>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
Expand Down
85 changes: 75 additions & 10 deletions l10n_it_asset_management/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ def setUpClass(cls):
],
limit=1,
)
cls.sale_journal = cls.env["account.journal"].search(
[
("type", "=", "sale"),
],
limit=1,
)

cls.civilistico_asset_dep_type = cls.env.ref(
"l10n_it_asset_management.ad_type_civilistico"
Expand Down Expand Up @@ -264,18 +270,48 @@ def _create_entry(self, account, amount, post=True):
self.assertEqual(entry.move_type, "entry")
return entry

def _update_asset(self, entry, asset):
"""Execute the wizard on `entry` to update `asset`."""
wizard_action = entry.open_wizard_manage_asset()
wizard_model = self.env[wizard_action["res_model"]]
wizard_context = wizard_action["context"]
def _create_sale_invoice(self, asset, amount=7000, invoice_date=None, post=True):
sale_invoice = self.env["account.move"].create(
{
"move_type": "out_invoice",
"invoice_date": invoice_date,
"partner_id": self.env.ref("base.partner_demo").id,
"journal_id": self.sale_journal.id,
"invoice_line_ids": [
Command.create(
{
"account_id": asset.category_id.asset_account_id.id,
"quantity": 1,
"price_unit": amount,
},
)
],
}
)
if post:
sale_invoice.action_post()
return sale_invoice

wizard_form = Form(wizard_model.with_context(**wizard_context))
wizard_form.management_type = "update"
wizard_form.asset_id = asset
wizard = wizard_form.save()
def _refund_move(self, move, method="cancel", ref_date=None):
reverse_context = {
"active_model": move._name,
"active_ids": move.ids,
}
refund_wizard_form = Form(
self.env["account.move.reversal"].with_context(**reverse_context)
)
refund_wizard_form.reason = "test"
if ref_date:
refund_wizard_form.date_mode = "custom"
refund_wizard_form.date = ref_date
refund_wizard_form.refund_method = method
refund_wizard = refund_wizard_form.save()

return wizard.link_asset()
refund_action = refund_wizard.reverse_moves()
refund_move = self.env[refund_action["res_model"]].browse(
refund_action["res_id"]
)
return refund_move

def _civil_depreciate_asset(self, asset):
# Keep only one civil depreciation
Expand Down Expand Up @@ -350,3 +386,32 @@ def _get_report(self, report_date, report_type):
report_ids = report_result["context"]["report_action"]["context"]["active_ids"]
report = self.env[report_model].browse(report_ids)
return report

def _get_move_asset_wizard(self, move, link_management_type, wiz_values=None):
"""Get the wizard that links `move` to an asset
with mode `link_management_type`.
`wiz_values` are values to be set in the wizard.
"""
if wiz_values is None:
wiz_values = {}

Check warning on line 396 in l10n_it_asset_management/tests/common.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_asset_management/tests/common.py#L396

Added line #L396 was not covered by tests

wiz_action_values = move.open_wizard_manage_asset()
wiz_form = Form(
self.env["wizard.account.move.manage.asset"].with_context(
**wiz_action_values["context"]
)
)
wiz_form.management_type = link_management_type
for field_name, field_value in wiz_values.items():
setattr(wiz_form, field_name, field_value)
wiz = wiz_form.save()
return wiz

def _link_asset_move(self, move, link_management_type, wiz_values=None):
"""Link `move` to an asset with mode `link_management_type`.
`wiz_values` are values to be set in the wizard.
"""
wiz = self._get_move_asset_wizard(
move, link_management_type, wiz_values=wiz_values
)
return wiz.link_asset()
Loading

0 comments on commit 0751cd8

Please sign in to comment.