İçereği Atla
Menü
Bu soru işaretlendi
4 Cevaplar
656 Görünümler

Hi i try to validate delivery but get error message and delivery slip is not create.

Do you know to to solve this problem?


RPC_ERROR

Odoo Server Error


Traceback (most recent call last):
  File "<198>", line 142, in template_198
  File "<198>", line 42, in template_198_content
KeyError: 'doc'

 

Avatar
Vazgeç
En İyi Yanıt

Hi,


The error KeyError: 'doc' happens when the delivery slip report tries to use a variable doc that hasn’t been defined.


Odoo provides a variable called docs (a list of records), but the template is using doc without setting it first.


This usually happens in a custom module or a modified delivery slip report template.


To check this, activate Developer Mode > go to Technical > Reports > Reports > search for Delivery Slip > open the related QWeb template.


If you see something like <t t-esc="doc.name"/>, but there’s no doc defined, that’s the cause of the error.


To fix it, add <t t-set="doc" t-value="docs[0]"/> before using doc if only one record is printed.


If the report is for multiple deliveries, wrap your code in <t t-foreach="docs" t-as="doc"> ... </t> to make doc available.


After updating the template, upgrade your custom module and try validating the delivery again-the slip should now be created without errors.



Hope it helps

Avatar
Vazgeç
Üretici

I followed your instruction but key error is change to "o"

odoo.addons.base.models.ir_qweb.QWebException: Error while render the template
KeyError: 'o'
Template: stock.report_delivery_document
Path: /t/t/t/t[2]
Node: <t t-set="partner" t-value="o.partner_id or (o.move_ids and o.move_ids[0].partner_id) or False"/>

code i updated as below; in report_deliveryslip

<t t-name="stock.report_deliveryslip">
<t t-set="doc" t-value="docs[0]"/>
<t t-foreach="docs" t-as="doc">
<t t-call="stock.report_delivery_document" t-lang="doc._get_report_lang()"/>
</t>
</t>

Üretici En İyi Yanıt

Finally, i did go to the template : web.address_layout (Customize by studioX)

 and delete  "Inherited View" and all work deliveryslip can print out.


Thank you for all help.


I appreciated.

Avatar
Vazgeç
En İyi Yanıt

The error message KeyError: 'doc' in Odoo when validating a delivery slip indicates that the system is trying to access a variable or key named 'doc' that doesn't exist in the template or code being executed. This often occurs during the report generation process.

Here are steps to troubleshoot and resolve this problem:

1. Identify the specific report template:

  • The traceback indicates the error is within a template file <198>. You'll need to find the exact name of the delivery slip template being used.
  • In Odoo, go to Settings > Technical > Reporting > Reports. Search for "Delivery Slip" or a similar name related to delivery operations.
  • Once you find the report, examine its External ID (e.g., stock.report_delivery_slip). This ID helps identify the associated QWeb template.
  • Then, navigate to Settings > Technical > User Interface > Views and search for the external ID of the report to find the corresponding view.

2. Examine the QWeb template:

  • Open the QWeb view identified in the previous step.
  • Carefully review the template code, looking for where the variable doc is used. The error KeyError: 'doc' means that the code is trying to access a dictionary key or object property named doc, but it's not available in the context.
  • Possible causes:
    • Typo: A simple typo in the template code when referencing doc.
    • Missing Definition: The variable doc is not being properly passed or defined within the template's context.
    • Incorrect Context: The template is expecting a different type of object than what's being provided.

3. Check the report's Python code:

  • The QWeb template receives its data from a Python class. You need to find the Python code that generates the data for the delivery slip report.
  • Go to Settings > Technical > Actions > Reports. Find the delivery slip report. Check the "Model" field. This tells you which Odoo model is used as the basis for the report (e.g., stock.picking).
  • Examine the code related to that model, especially any methods that are called when generating the delivery slip. Look for how the doc variable (or its equivalent) is being prepared and passed to the QWeb template.
  • Possible issues:
    • The Python code is not correctly fetching or preparing the data that the template expects.
    • The doc variable is not being added to the context dictionary that's passed to the template.

4. Solutions

  • Correct the template: If there's a typo or missing definition in the QWeb template, fix it. Ensure that doc is correctly referenced and that all necessary data is available in the template's context.
  • Modify the Python code: If the Python code is not providing the correct data, adjust it to fetch the required information and pass it to the template. Make sure the doc variable (or its equivalent) is properly populated.
  • Check for customizations: If you or someone else has customized the delivery slip report, review those changes carefully. Customizations are often the source of such errors.
  • Update Odoo: If you're using an older version of Odoo, consider updating to the latest stable release. Bug fixes and improvements in newer versions might resolve the issue.
  • Check installed modules: In some cases, this error can be caused by a faulty or incompatible module. Try disabling recently installed modules to see if that resolves the issue.

Example Scenario and Solution

Let's say the delivery slip template has this line:

<span t-esc="doc.name"/>

And the Python code preparing the data looks like this:

def _get_report_values(self, docids, data=None):
    docs = self.env['stock.picking'].browse(docids)
    return {
        'doc_ids': docids,
        'doc': docs,
    }

In this case, doc is a collection of stock.picking records. To access the name of the first record, you should modify the template:

<span t-esc="doc[0].name"/>

Avatar
Vazgeç
En İyi Yanıt
Cause

Your QWeb report (usually stock.report_deliveryslip_document ) tries to use the variable doc , but it's not defined .

In Odoo, the report engine passes a variable called docs (a recordset). If you use doc , you must define it first.


Step-by-Step Fix:
  1. Go to Developer Mode
    • Activate Developer Mode in Odoo.
  2. Navigate to QWeb Views
    • Menu: Technical → User Interface → Views
    • Search for the delivery slip template:
      Example: stock.report_deliveryslip_document (or your custom report)
  3. Edit the Template

At the top of the XML , add this line right after the opening <t> tag:

<t t-set="doc" t-value="docs[0]"/>
Example of Correct Template Structure
<t t-name="stock.report_deliveryslip_document">
  <t t-call="web.html_container">
    <t t-set="doc" t-value="docs[0]"/> <!-- ✅ Fix line -->
    <div class="page">
      <h2 t-esc="doc.name"/> <!-- Example usage -->
      <p t-esc="doc.partner_id.name"/>
      <!-- Your report content -->
    </div>
  </t-call>
</t>

This sets doc = docs[0] , so all your t-esc="doc.xyz" calls now work.

Why This Fix Works
  • docs is the standard list of records Odoo passes into QWeb reports.
  • If you're using doc , but it isn't defined from docs[0] , you get a KeyError .


Thanks & Regards,

Email: contact@datainteger.com 

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Ağu 20
3402
4
Tem 25
2278
2
Şub 25
5455
0
Ağu 24
1339
2
Tem 24
1864