Skip to content

[6788][ADD] maintenance_additional_attributes: add specific attributes - #9

Open
smorita7749 wants to merge 16 commits into
18.0from
6788-add-maintenance_equipment_additional_attributes
Open

[6788][ADD] maintenance_additional_attributes: add specific attributes#9
smorita7749 wants to merge 16 commits into
18.0from
6788-add-maintenance_equipment_additional_attributes

Conversation

@smorita7749

@smorita7749 smorita7749 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

QT6788

Add a new module that extends maintenance.equipment with RBKK-specific attributes:

  • Set Name (Char)
  • General Name (Many2one master, creatable inline; managed under Maintenance / Configuration)
  • National Project ID (Many2one master; managed under Maintenance / Configuration)
  • Fixed Asset flag + Fixed Asset Code (shown only when Fixed Asset is set)
  • GMP flag + GMP Function (Manufacturing / QC) + GMP Category (A / B / C), shown only when GMP is set
  • Measuring Instrument flag
  • Used in location (Many2one stock.location, internal locations only, tracked) — replaces the base free-text location on the form
  • Manufacturer (Char)
  • Acquisition Date (Date)

Includes Japanese translation (i18n/ja.po).

…butes to maintenance equipment

Extend maintenance.equipment with RBKK-specific attributes: set name,
general name (master), national project (master), fixed asset flag/code,
GMP flag with function and category, measuring instrument flag, location
in use (stock.location), manufacturer and acquisition date.

task-6788
…layout

These two modules were dropped by the ours-style merge c2fe042 ("fixup!"),
which recorded 54185f3 as a parent but kept only the feature branch tree.
Recover them unchanged from 54185f3.
…ription

Also dropped by the ours-merge c2fe042: test-requirements.txt (test dep
stock_reporting_access needed by stock_location_report_manager_layout) and
the regenerated purchase_security_adjust static description. Recover from 54185f3.
@smorita7749
smorita7749 force-pushed the 6788-add-maintenance_equipment_additional_attributes branch from 8056cb8 to f455cb1 Compare July 16, 2026 01:18
@smorita7749
smorita7749 force-pushed the 6788-add-maintenance_equipment_additional_attributes branch from f455cb1 to 66565d6 Compare July 22, 2026 10:43
@smorita7749
smorita7749 force-pushed the 6788-add-maintenance_equipment_additional_attributes branch from 159c59f to d254fa3 Compare July 23, 2026 15:27
@smorita7749

Copy link
Copy Markdown
Contributor Author

Add ja.po

Translation notes

Translations are referenced from existing Odoo translations where available (odoo/maintenance, odoo/purchase).

The following terms have no reference and are translated independently:

msgid msgstr
Alert Period アラート期間
Alert Period Uom アラート期間の単位
Alert Sent アラート送信済み
Amount of time before the scheduled date at which the responsible user should be alerted about this maintenance. 予定日より前に担当者へアラートを通知する期間。

Comment thread maintenance_additional_attributes/models/maintenance_equipment.py
Comment thread maintenance_additional_attributes/models/maintenance_request.py Outdated
Comment thread maintenance_additional_attributes/models/maintenance_request.py Outdated
- Rename alert_period_uom to alert_period_unit
- Add unique name constraint on equipment department and general name
- Simplify alert_sent field definition
Comment thread maintenance_additional_attributes/models/maintenance_equipment.py
Comment thread maintenance_additional_attributes/models/maintenance_request.py
Comment on lines +12 to +24
<record id="maintenance_equipment_department_view_form" model="ir.ui.view">
<field name="name">maintenance.equipment.department.form</field>
<field name="model">maintenance.equipment.department</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="name" />
</group>
</sheet>
</form>
</field>
</record>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Editable list view is enough.

Suggested change
<record id="maintenance_equipment_department_view_form" model="ir.ui.view">
<field name="name">maintenance.equipment.department.form</field>
<field name="model">maintenance.equipment.department</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="name" />
</group>
</sheet>
</form>
</field>
</record>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

<record id="maintenance_equipment_department_action" model="ir.actions.act_window">
<field name="name">Departments</field>
<field name="res_model">maintenance.equipment.department</field>
<field name="view_mode">list,form</field>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<field name="view_mode">list,form</field>
<field name="view_mode">list</field>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@smorita7749
smorita7749 force-pushed the 6788-add-maintenance_equipment_additional_attributes branch from 0b371d3 to 36d5f1e Compare August 5, 2026 02:42
@smorita7749 smorita7749 changed the title [6788][ADD] maintenance_equipment_additional_attributes: add specific attributes to maintenance equipment [6788][ADD] maintenance_additional_attributes: add specific attributes Aug 5, 2026
@smorita7749

Copy link
Copy Markdown
Contributor Author

Pushed 8a06573 to 6788-add-maintenance_equipment_additional_attributes.

Close date can now be recorded before completion

The form already exposed close_date as editable, but the standard create() clears it while the request is not in a done stage, and the standard write() rewrites it on every stage change (today() on completion, empty otherwise). A date entered before completion was therefore always discarded, and the previous restore only worked when close_date and stage_id were written together.

create() is now overridden to restore the entered date, and write() snapshots the stored value before super() instead of reading it back from vals. When no date was ever recorded, the standard behavior of stamping the completion date still applies.

Maintenance alert fixes

  • The alert now falls back to the technician set on the equipment. maintenance.request.user_id only depends on company_id and equipment_id, so a technician assigned to the equipment after the request was created is never propagated.
  • The summary, the note and the scheduled date are rendered in the assigned user's language and timezone. They were previously rendered for the user running the cron, so a Japanese technician received an English note with a UTC timestamp.
  • alert_sent is only set when an activity was actually created. activity_schedule() returns False when the automation is skipped, and the alert was permanently lost in that case.
  • The cron record now runs as OdooBot. Without an explicit user_id it ran as whoever installed the module, and the record rules on maintenance.request silently limited the alerts to that user's own and followed requests.
  • Both data files are now noupdate="1", so the cron interval and the activity type survive a module upgrade.

Views

  • New list and search views for the equipment. None of the fields added by this module were reachable from either, so equipment could not be filtered by management number, fixed asset code, manufacturer or serial number, nor grouped by department, general name or location. Department, general name and location default to visible; the rest are optional="hide".
  • The equipment form fields are split between both columns. All nine were inserted after category_id, which put them in the left column, leaving 13 fields on the left against 3 on the right.
  • The request form view XML ID is renamed to maintenance_request_view_form to match the model.

Tests

Adds tests/ with 9 tests covering the close date behavior and the alert cron (period window, single send, reset on reschedule, technician assignment and the equipment fallback).

# No date was ever recorded: let the standard behavior of
# stamping the completion date apply.
continue
close_date = fields.Date.to_date(close_date)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

def _cron_send_maintenance_alerts(self):
requests = self.search(
[
("archive", "=", False),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need? Doesn't odoo search for active record?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed. maintenance.request has no active field and uses an archive bool instead, so active_test doesn't apply and archived records are returned by search().

Also, cancelling a request doesn't change its stage, so without this condition alerts would be sent for cancelled requests.

@smorita7749

Copy link
Copy Markdown
Contributor Author

Pushed 82b22fe to 6788-add-maintenance_equipment_additional_attributes.

 maintenance_additional_attributes/models/maintenance_request.py | 53 +++++++++-----------
 maintenance_additional_attributes/tests/test_maintenance_request.py |  6 +++
 2 files changed, 30 insertions(+), 29 deletions(-)

Reworked how the close date is protected in create()/write().

Instead of letting the standard behavior rewrite close_date and restoring it afterwards, the standard update is now simply not applied. The standard create()/write() derive the close date from the stage through ORM writes (close_date alone), so they come back to our own write(), where they are ignored — except for the requests that have no date recorded yet, so that the standard stamping of the completion date still applies there.

This removes the snapshot dictionary, the three-way branch, the zip(..., strict=True) pairing and the fields.Date.to_date() normalization that was questioned in the review, and it no longer writes the close date twice.

Also added a regression test for the context leak this uncovered: create() returned the requests in the environment carrying the internal context, so a subsequent write of the close date alone was silently ignored. Fixed with with_env(self.env).

Tests: 12 passed, 0 failed.

Add is_national_project (Boolean) and rename national_project to
national_project_name, which is now only shown when the flag is set,
following the fixed asset and GMP fields.
@smorita7749

Copy link
Copy Markdown
Contributor Author

National project is now gated by a flag

The national project was a bare Char, so there was no way to tell "not a national project" from "national project whose name has not been entered yet", and the field was always shown.

  • is_national_project (Boolean, National Project) is added, and the existing national_project Char is renamed to national_project_name.
  • On the form, the name is only shown when the flag is set (invisible="not is_national_project"), the same pattern as is_fixed_asset / fixed_asset_code and is_gmp / management_no.
  • In the list view, the renamed name field is kept and the flag is added next to the other flags, both optional="hide".
  • ja.po: 国家プロジェクト now maps to the flag, and 国家プロジェクト名 is added for the name.

The module is not deployed yet, so the rename needs no data migration.

No search filter was added for the flag; happy to add one alongside Fixed Asset / GMP / Measuring Instrument if that is wanted.

 maintenance_additional_attributes/i18n/ja.po                     | 7 ++++++-
 .../models/maintenance_equipment.py                              | 3 ++-
 .../views/maintenance_equipment_views.xml                        | 9 +++++++--

Pushed e7a22d7 to 6788-add-maintenance_equipment_additional_attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants