Initial commit: Core packages

This commit is contained in:
Ernad Husremovic 2025-08-29 15:20:45 +02:00
commit 12c29a983b
9512 changed files with 8379910 additions and 0 deletions

View file

@ -0,0 +1,91 @@
odoo.define('resource.section_backend', function (require) {
// The goal of this file is to contain JS hacks related to allowing
// section on resource calendar.
"use strict";
var FieldOne2Many = require('web.relational_fields').FieldOne2Many;
var fieldRegistry = require('web.field_registry');
var ListRenderer = require('web.ListRenderer');
var SectionListRenderer = ListRenderer.extend({
/**
* We want section to take the whole line (except handle and trash)
* to look better and to hide the unnecessary fields.
*
* @override
*/
_renderBodyCell: function (record, node, index, options) {
var $cell = this._super.apply(this, arguments);
var isSection = record.data.display_type === 'line_section';
if (isSection) {
if (node.attrs.widget === "handle") {
return $cell;
} else if (node.attrs.name === "display_name") {
var nbrColumns = this._getNumberOfCols();
if (this.handleField) {
nbrColumns--;
}
if (this.addTrashIcon) {
nbrColumns--;
}
$cell.attr('colspan', nbrColumns);
} else {
return $cell.addClass('o_hidden');
}
}
return $cell;
},
/**
* We add the o_is_{display_type} class to allow custom behaviour both in JS and CSS.
*
* @override
*/
_renderRow: function (record, index) {
var $row = this._super.apply(this, arguments);
if (record.data.display_type) {
$row.addClass('o_is_' + record.data.display_type);
}
return $row;
},
/**
* We want to add .o_section_list_view on the table to have stronger CSS.
*
* @override
* @private
*/
_renderView: function () {
var self = this;
return this._super.apply(this, arguments).then(function () {
self.$('.o_list_table').addClass('o_section_list_view');
// Discard the possibility to remove the sections
self.$('.o_is_line_section .o_list_record_remove').remove()
});
},
});
// We create a custom widget because this is the cleanest way to do it:
// to be sure this custom code will only impact selected fields having the widget
// and not applied to any other existing ListRenderer.
var SectionFieldOne2Many = FieldOne2Many.extend({
/**
* We want to use our custom renderer for the list.
*
* @override
*/
_getRenderer: function () {
if (this.view.arch.tag === 'tree') {
return SectionListRenderer;
}
return this._super.apply(this, arguments);
},
});
fieldRegistry.add('section_one2many', SectionFieldOne2Many);
});

View file

@ -0,0 +1,8 @@
// The goal of this file is to contain CSS hacks related to allowing
// section on resource calendar.
table.o_section_list_view tr.o_data_row.o_is_line_section {
font-weight: bold;
background-color: #DDDDDD;
border-top: 1px solid #BBB;
border-bottom: 1px solid #BBB;
}

View file

@ -0,0 +1,57 @@
/** @odoo-module */
import { ListRenderer } from "@web/views/list/list_renderer";
const { useEffect } = owl;
export class SectionListRenderer extends ListRenderer {
setup() {
super.setup();
this.displayType = "line_section";
this.titleField = "title";
useEffect(
(table) => {
if (table) {
table.classList.add("o_section_list_view");
}
},
() => [this.tableRef.el]
);
}
getColumns(record) {
const columns = super.getColumns(record);
if (this.isSection(record)) {
return this.getSectionColumns(columns);
}
return columns;
}
getRowClass(record) {
const classNames = super.getRowClass(record).split(" ");
if (this.isSection(record)) {
classNames.push(`o_is_${this.displayType}`, `fw-bold`);
}
return classNames.join(" ");
}
getSectionColumns(columns) {
const sectionColumns = columns.filter((col) => col.widget === "handle");
let colspan = columns.length - sectionColumns.length;
if (this.activeActions.onDelete) {
colspan++;
}
const titleCol = columns.find(
(col) => col.type === "field" && col.name === this.titleField
);
sectionColumns.push({ ...titleCol, colspan });
return sectionColumns;
}
isSection(record) {
return record.data.display_type === this.displayType;
}
}
SectionListRenderer.recordRowTemplate = "resource.SectionListRenderer.RecordRow";

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="resource.SectionListRenderer.RecordRow" t-inherit="web.ListRenderer.RecordRow" owl="1">
<xpath expr="//t[@t-if='displayOptionalFields or hasX2ManyAction']" position="attributes">
<attribute name="t-if">(displayOptionalFields or hasX2ManyAction) and !isSection(record)</attribute>
</xpath>
</t>
</templates>

View file

@ -0,0 +1,18 @@
/** @odoo-module */
import { SectionListRenderer } from "./section_list_renderer";
import { registry } from "@web/core/registry";
import { X2ManyField } from "@web/views/fields/x2many/x2many_field";
class SectionOneToManyField extends X2ManyField {}
SectionOneToManyField.components = {
...X2ManyField.components,
ListRenderer: SectionListRenderer,
};
SectionOneToManyField.defaultProps = {
...X2ManyField.defaultProps,
editable: "bottom",
};
SectionOneToManyField.additionalClasses = ['o_field_one2many'];
registry.category("fields").add("section_one2many", SectionOneToManyField);