Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
1905 Tampilan

Hello, I need some help with a custom plugin for Odoo 16. 

I want to create a feature that when I drag a card to a certain column in kanban, it will show a confirmation window and if I agree, it will move the card to the desired column and open a new form from another custom plugin with filled fields that match the fields of the card in kanban. 

The main problem is that I don’t understand how to properly extend the setup in the extended component and get and pass the data to the new form (as I understand, the standard approach is to use default_)

My current code is something like this:

** @odoo-module **/
import { KanbanDynamicGroupList, KanbanModel } from “@web/views/kanban/kanban_model”;
export class LeadKanbanModel extends KanbanModel {}
class LeadKanbanDynamicGroupList extends KanbanDynamicGroupList {

    /**
* @param {string} dataRecordId
* @param {string} dataGroupId
* @param {string} refId
* @param {string} targetGroupId
*/


async moveRecord(dataRecordId, dataGroupId, refId, targetGroupId) {
    const targetGroup = this.groups.find((g) => g.id === targetGroupId);
    const sourceGroup = this.groups.find((g) => g.id === dataGroupId);

    if (!sourceGroup || !targetGroup) {
        return; // Groups have been re-rendered, old ids are ignored
    }

    if (targetGroup.displayName == "Завершён") {
        const record = sourceGroup.list.records.find((r) => r.id === dataRecordId);
        if (!record) return;
       
        let that = this;
        const superMoveRecord = super.moveRecord.bind(this);

        var Dialog = require('web.Dialog');
        var myDialog = new Dialog(this, {
            title: 'Do you want to complete the lead?',
            size: 'medium',
            $content: $('
').css({
                display: 'flex',
                alignItems: 'center',
                flexWrap: 'nowrap',
            })
            .append($('').text('Close the lead and open the work order')).css({ whiteSpace: 'nowrap' }),
            buttons: [
                {text: 'Yes', classes: 'btn-primary', close: true, click: function() {
// here
superMoveRecord(dataRecordId, dataGroupId, refId, targetGroupId);
},
                {text: 'No', classes: 'btn-primary', close: true, click: () => {
}}
            ]
        });
      myDialog.open();
        return true;
  } return await super.moveRecord(dataRecordId, dataGroupId, refId, targetGroupId);   
}
}

LeadKanbanModel.DynamicGroupList = LeadKanbanDynamicGroupList;



Avatar
Buang
Penulis Jawaban Terbai

UPD: This is indeed a very crooked solution, but to be honest the OWL documentation is a bit of a pain.  

So far, my solution is to use relatively pure js, because it is easier as strange as it sounds. in custom_addons\market-crm\static\src\components\leads_kanban\kanban_model.js I wrote the opening of the window and storing the context in local storage: 

...

var Dialog = require('web.Dialog');
            var myDialog = new Dialog(this, {
                title: 'Do you want to complete the lead?',
                size: 'medium',
                $content: $('
').css({
                    display: 'flex',
                    alignItems: 'center',
                    flexWrap: 'nowrap',
                })
                .append($('').text('Close the lead and open the order form')).css({ whiteSpace: 'nowrap' }),
                buttons: [
                    {text: 'Yes', classes: 'btn-primary', close: true, click: () => {
                        superMoveRecord(dataRecordId, dataGroupId, refId, targetGroupId);
                        var currentUrl = window.location.href;
                        var index = currentUrl.indexOf("/web#");
                        var baseUrl = currentUrl.slice(0, index);
                        var newUrl = baseUrl + "/web#cids=1&menu_id=214&action=319&model=idiamarket_sale.order&view_type=form";
                        localStorage.setItem ("contact_number", record.data.contact_number);
                        localStorage.setItem ("contact_name", record.data.contact_name);
                        window.open(newUrl, "_blank");
                    },
                },
...

and in the form that should open custom_addons\market_sale\static\src\components\order_form\form_controller.js we get the data from local storage and substitute. 
UPD: problems with isDirty etc, kind of fix:


** @odoo-module **/
import {FormController} from "@web/views/form/form_controller";
import {onRendered, onMounted, onWillPatch, onPatched, onWillUnmount} from "@odoo/owl";
import {ADD_PRODUCT_CHANNEL} from "../order_fake_product_tree_view/constants";
import core from "web.core";
export class CustomFormController extends FormController {
    setup() {
        super.setup();
        onRendered(() => {
            var input_phone = document.getElementById("partner_phone");
            if (input_phone) {
                input_phone.addEventListener("input", () => {
                    var new_contact_number = input_phone.value;
                    localStorage.setItem("contact_number", new_contact_number);
                  });
            }
          });
        onMounted(async () => {
            core.bus.on(ADD_PRODUCT_CHANNEL, this, this.addRecordToList);
            var contact_name = localStorage.getItem ("contact_name");
            var input = document.getElementById("partner");
            if (input) {
                input.value = contact_name;
            }
            var contact_number = localStorage.getItem ("contact_number");
            var input_phone = document.getElementById("partner_phone");
            if (input_phone) {
                input_phone.value = contact_number;
            }
        })
        onPatched(() => {
            var contact_name = localStorage.getItem ("contact_name");
            var input = document.getElementById("partner");
            if (input && !input.value) {
                input.value = contact_name;
            }
            var new_contact_number = localStorage.getItem ("contact_number");
            var input_phone = document.getElementById("partner_phone");
            if (input_phone) {
                input_phone.value = new_contact_number;
            }
          });
        onWillUnmount(() => {
            core.bus.off(ADD_PRODUCT_CHANNEL, this, this.addRecordToList);
            localStorage.removeItem("contact_number");
            localStorage.removeItem("contact_name");
        })
    }
    async addRecordToList() {
        await this.model.load();
    }
}


Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
0
Feb 25
721
2
Agu 23
9803
1
Jun 23
2490
1
Jul 23
2054
0
Mei 23
2075