Skip to content

Commit 62f0719

Browse files
committed
[ADD] project_recognition_date_sync: add sync option for recognition dates.
When the project start date and recognition date differ, a button is shown to allow syncing them. This ensures recognition dates across invoices and journal entries remain consistent with the project start date - Added a button to sync recognition date with project start date. - Ensures consistency across invoices and journal entries. - Reduces manual adjustments for accounting accuracy.
1 parent dd31619 commit 62f0719

File tree

8 files changed

+132
-0
lines changed

8 files changed

+132
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import models
2+
from . import wizard
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
'name': 'Link project date with analytical account',
3+
'version': '1.0',
4+
'author': 'Aaryan Parpyani (aarp)',
5+
'depends': ['sale_project', 'account'],
6+
'installable': True,
7+
'application': False,
8+
'license': 'LGPL-3',
9+
'description': '''
10+
Changing the project start date will show a button to sync recognition dates
11+
across invoices and journal entries.
12+
Ensuring accounting accuracy without manual intervention.
13+
''',
14+
'data': [
15+
'views/project_project_views.xml',
16+
]
17+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import project_project
2+
from . import account_move_line
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# imports of odoo
2+
from odoo import fields, models
3+
4+
5+
class AccountMoveLine(models.Model):
6+
_inherit = 'account.move.line'
7+
8+
date_changed = fields.Date(string="Changed Date")
9+
10+
def action_automatic_entry(self, default_action=None):
11+
"""
12+
If account move line is linked to a saled order that is
13+
connected to a project with a defined start date, that date
14+
is set as default date in wizard context.
15+
"""
16+
action = super().action_automatic_entry(default_action)
17+
ctx = dict(action.get('context', {}))
18+
19+
project = self.move_id.line_ids.sale_line_ids.order_id.project_id
20+
if project and project.date_start:
21+
ctx['default_date'] = project.date_start
22+
23+
action['context'] = ctx
24+
return action
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# imports of odoo
2+
from odoo import api, fields, models
3+
4+
5+
class Project(models.Model):
6+
_inherit = 'project.project'
7+
8+
is_sync_required = fields.Boolean(compute="_compute_is_sync_required", string="Is sync required?")
9+
move_lines = fields.One2many('account.move.line', compute="_compute_is_sync_required", string="Move lines")
10+
11+
# Method returns account move lines (invoice lines) that needs synchronization.
12+
def _get_sync_required_move_lines(self):
13+
return self.env['account.move.line'].search([
14+
('move_id', 'in', self.sale_order_id.invoice_ids.ids),
15+
('date_changed', '!=', self.date_start),
16+
('move_type', '!=', 'entry'),
17+
('parent_state', '=', 'posted'),
18+
('account_internal_group', 'in', ['income', 'expense'])
19+
])
20+
21+
# Computes if synchronization is required based on related invoices and start date.
22+
@api.depends('sale_order_id.invoice_ids', 'date_start')
23+
def _compute_is_sync_required(self):
24+
self.move_lines = self._get_sync_required_move_lines()
25+
self.is_sync_required = bool(self.move_lines)
26+
27+
def open_recognition_date_sync_wizard(self):
28+
"""
29+
Open the recognition date synchronization wizard for related account move lines.
30+
31+
This method prepares the context with the relevant move line IDs and
32+
date and action values before launching the
33+
`account.account_automatic_entry_wizard_action` wizard.
34+
"""
35+
action = self.env.ref('account.account_automatic_entry_wizard_action').read()[0]
36+
37+
# Force the values of the move line in the context to avoid issues
38+
ctx = dict(self.env.context)
39+
ctx.pop('active_ids', None)
40+
ctx.pop('default_journal_id', None)
41+
ctx['active_ids'] = self.move_lines.ids
42+
ctx['active_model'] = 'account.move.line'
43+
ctx['default_action'] = 'change_period'
44+
ctx['default_date'] = self.date_start
45+
46+
action['context'] = ctx
47+
return action
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<odoo>
2+
<data>
3+
<record id="project_project_form_inherit_view" model="ir.ui.view">
4+
<field name="name">project.project.form.inherit.view</field>
5+
<field name="model">project.project</field>
6+
<field name="inherit_id" ref="project.edit_project"/>
7+
<field name="arch" type="xml">
8+
<xpath expr="//form/header" position="after">
9+
<div class="alert alert-info" role="alert" invisible="not is_sync_required">
10+
You have still journal items needs to be recognised from <field name="date_start" class="fw-bold" readonly="1"></field>
11+
</div>
12+
</xpath>
13+
14+
<xpath expr="//field[@name='date']" position="after">
15+
<button name="open_recognition_date_sync_wizard" type="object"
16+
string="Sync Recognition Date" help="Recompute the recognition date based on the project start date"
17+
icon="fa-refresh" class="btn-link mb-1 px-0" invisible="not is_sync_required"/>
18+
</xpath>
19+
</field>
20+
</record>
21+
</data>
22+
</odoo>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import recognition_date_sync_wizard
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# imports of odoo
2+
from odoo import models
3+
4+
5+
class RecognitionDateSyncWizard(models.TransientModel):
6+
_inherit = 'account.automatic.entry.wizard'
7+
8+
def do_action(self):
9+
"""
10+
Set the date_changed field of the related account move lines
11+
with the wizard's date, then call the parent method.
12+
"""
13+
self.env['account.move.line'].browse(self._context.get('active_ids', [])).write({
14+
'date_changed': self.date
15+
})
16+
17+
return super().do_action()

0 commit comments

Comments
 (0)