Skip to content

Commit

Permalink
T1771 Migrate recurring_contract to v17
Browse files Browse the repository at this point in the history
  • Loading branch information
ecino committed Sep 9, 2024
1 parent 55fb581 commit beea78b
Show file tree
Hide file tree
Showing 22 changed files with 213 additions and 650 deletions.
10 changes: 0 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,6 @@ repos:
hooks:
- id: pyupgrade
args: ["--keep-percent-format"]
- repo: https://github.com/acsone/setuptools-odoo
rev: 3.1.8
hooks:
- id: setuptools-odoo-make-default
- id: setuptools-odoo-get-requirements
args:
- --output
- requirements.txt
- --header
- "# generated from manifests external_dependencies"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
hooks:
Expand Down
14 changes: 14 additions & 0 deletions recurring_contract/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ generated for each group.
.. contents::
:local:

Configuration
=============

1. Make sure you have the full accounting features enabled in your
account. In order to do this, go in Settings/Users& Companies/Groups
and search for "Show Full Accounting Features". Add your user to the
group.
2. Make sure you have products with the Income account property set. On
a product page, go to the "Accounting" tab and set the "Income
account" field.
3. Make sure you have at least one Journal of type Sale in your company.
The first journal of type Sale will be used to post the income from
the recurring contracts.

Usage
=====

Expand Down
1 change: 0 additions & 1 deletion recurring_contract/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from . import models
from . import wizards
from . import tools
2 changes: 1 addition & 1 deletion recurring_contract/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{
"name": "Recurring contract",
"summary": "Contract for recurring invoicing",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"author": "Compassion CH",
"development_status": "Production/Stable",
Expand Down
18 changes: 8 additions & 10 deletions recurring_contract/data/balance_product_for_migr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
@author Simon Gonzalez <[email protected]>
The licence is in the file __manifest__.py
-->
<odoo>
<data noupdate="1">
<!-- PRODUCT FOR THE MIGRATION 14.0.1.0.5 -->
<record id="product_balance_migr" model="product.product">
<field name="name">Balance</field>
<field name="type">consu</field>
<field name="default_code">TODO MODIFY</field>
<field name="categ_id">1</field>
</record>
</data>
<odoo noupdate="1">
<!-- PRODUCT FOR THE MIGRATION 14.0.1.0.5 -->
<record id="product_balance_migr" model="product.product">
<field name="name">Balance</field>
<field name="type">consu</field>
<field name="default_code">TODO MODIFY</field>
<field name="categ_id">1</field>
</record>
</odoo>
12 changes: 10 additions & 2 deletions recurring_contract/data/pricelist_item_base_automation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
The licence is in the file __manifest__.py
-->
<odoo>
<record model="ir.actions.server" id="action_pricelist_item_update">
<field name="name">Update contract line amount</field>
<field name="model_id" ref="product.model_product_pricelist_item" />
<field name="state">code</field>
<field name="code">records.update_cl_amount()</field>
</record>
<record id="automated_action" model="base.automation">
<field
name="name"
Expand All @@ -18,7 +24,9 @@
/>
<field name="trg_date_range">0</field>
<field name="trg_date_range_type">minutes</field>
<field name="state">code</field>
<field name="code">records.update_cl_amount()</field>
<field
name="action_server_ids"
eval="[(4, ref('action_pricelist_item_update'))]"
/>
</record>
</odoo>
22 changes: 14 additions & 8 deletions recurring_contract/models/contract_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class ContractGroup(models.Model):
"customer in january.",
default=1,
)
company_id = fields.Many2one(
"res.company",
"Company",
default=lambda self: self.env.company,
index=True,
)
payment_mode_id = fields.Many2one(
"account.payment.mode",
"Payment mode",
Expand All @@ -58,7 +64,6 @@ class ContractGroup(models.Model):
string="Invoice Suspended Until",
help="Date at which the sponsor should receive invoices again.",
tracking=True,
states={"draft": [("readonly", False)]},
)
partner_id = fields.Many2one(
"res.partner",
Expand Down Expand Up @@ -485,13 +490,18 @@ def _build_invoice_gen_data(
journal = self.env["account.journal"].search(
[("type", "=", "sale"), ("company_id", "=", company_id)], limit=1
)
if not journal:
raise UserError(
_("No sale journal found for company %s")
% reference_contract.company_id.name
)
inv_data = {
"payment_reference": self.ref, # Accountant reference
"ref": self.ref, # Internal reference
"move_type": "out_invoice",
"partner_id": partner_id,
"journal_id": journal.id,
"currency_id": reference_contract.pricelist_id.currency_id.id,
"currency_id": reference_contract.currency_id.id,
"invoice_date": invoicing_date, # Accountant date
"recurring_invoicer_id": invoicer.id,
"pricelist_id": reference_contract.pricelist_id.id,
Expand Down Expand Up @@ -547,15 +557,11 @@ def build_inv_line_data(
contract = contract_line.contract_id
line_name = product.name
if contract_line.pricelist_item_count:
price = contract.pricelist_id.get_product_price(
product, qty, contract.partner_id, invoicing_date
price = contract.pricelist_id._get_product_price(
product, qty, date=invoicing_date
)
else:
price = contract_line.amount
if product.pricelist_item_count > 0:
price = contract.pricelist_id.get_product_price(
product, qty, self.partner_id, invoicing_date
)
elif gift_wizard:
product = gift_wizard.product_id
qty = gift_wizard.quantity
Expand Down
20 changes: 4 additions & 16 deletions recurring_contract/models/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,9 @@ def _compute_last_payment(self):
else:
invoice.last_payment = False

def register_payment(
self, payment_line, writeoff_acc_id=False, writeoff_journal_id=False
):
def action_register_payment(self):
"""After registering a payment post a message of the bank statement linked"""
out = super().register_payment(
payment_line, writeoff_acc_id, writeoff_journal_id
)
out = super().action_register_payment()
self.message_post_bank_statement_notes()
return out

Expand All @@ -74,22 +70,14 @@ def _get_bank_statement_notes(self):
)
return statement_line_ids.filtered("narration").mapped("narration")

def action_invoice_paid(self):
def _invoice_paid_hook(self):
"""Call invoice_paid method on related contracts."""
res = super().action_invoice_paid()
res = super()._invoice_paid_hook()
for invoice in self:
contracts = invoice.mapped("invoice_line_ids.contract_id")
contracts.invoice_paid(invoice)
return res

def action_invoice_re_open(self):
"""Call invoice_unpaid method on related contract."""
res = super().action_invoice_re_open()
for invoice in self:
contracts = invoice.mapped("invoice_line_ids.contract_id")
contracts.invoice_unpaid(invoice)
return res

def reconcile_after_clean(self):
"""
Called after clean invoices. If invoices can be reconciled
Expand Down
13 changes: 1 addition & 12 deletions recurring_contract/models/move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#
##############################################################################

from odoo import _, api, fields, models
from odoo import _, fields, models
from odoo.exceptions import UserError


Expand All @@ -34,17 +34,6 @@ class MoveLine(models.Model):
related="move_id.payment_state", store=True, readonly=True, index=True
)

@api.onchange("product_id")
def _onchange_product_id(self):
# workaround an odoo bug :
# could be fixed by applying this change here
# - self.analytic_tag_ids = rec.analytic_tag_ids.ids
# + self.analytic_tag_ids = rec.analytic_tag_ids
# https://github.com/odoo/odoo/blame/12.0/addons/account_analytic_default/models/account_analytic_default.py#L100
self.analytic_tag_ids = self.env["account.analytic.tag"]
res = super()._onchange_product_id()
return res

def group_reconcile(self, matched_lines, credit_or_debit="debit"):
"""
Will reconcile the current recordset with any required lines taken from the
Expand Down
4 changes: 2 additions & 2 deletions recurring_contract/models/product_pricelist_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def update_cl_amount(self):
]
)
for cl in contract_lines:
price = cl.contract_id.pricelist_id.get_product_price(
cl.product_id, cl.quantity, cl.contract_id.partner_id
price = cl.contract_id.pricelist_id._get_product_price(
cl.product_id, cl.quantity
)
if cl.amount != price:
cl.amount = price
Expand Down
Loading

0 comments on commit beea78b

Please sign in to comment.