I can change my Work Order sequence in my model fairly easy with this description link.
https://odootricks.tips/about/automated-actions/set-sequence-numbers-for-sales-orders/
i.e. in UI using developer mode.
When I try to code it .....
This part of my code (creating a new sequence) works fine:
<!-- New sequence for work.order -->
<record id="seq_work_order" model="ir.sequence">
<field name="name">Work Order</field>
<field name="code">work.order</field>
<field name="prefix">WO</field>
<field name="padding">3</field>
<field name="company_id" eval="False"/>
</record>
Whereas the part where I create the automated action:
<!-- Automated action for work.order -->
<record model="ir.actions.server" id="work_order_sequence">
<field name="name">Work Order Sequence Action</field>
<field name="model_id" ref="model_sale_order"/>
<field name="state">code</field>
<field name="code">
for record in records:
if record.order_type == "Workorder":
ref = env['ir.sequence'].next_by_code('work.order')
record['name'] = ref
</field>
</record>
Odoo creates the following error:
odoo.tools.convert.ParseError: "IndentationError : expected an indented block at line 3
ref = env['ir.sequence'].next_by_code('work.order')
None" while parsing /opt/odoo12/odoo/custom-addons/yachtservice/views/work_order_view.xml:60, near
<record model="ir.actions.server" id="work_order_sequence">
<field name="name">Work Order Sequence Action</field>
<field name="model_id" ref="model_sale_order"/>
<field name="state">code</field>
<field name="code">
for record in records:
if record.order_type == "Workorder":
ref = env['ir.sequence'].next_by_code('work.order')
record['name'] = ref
</field>
</record>
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Contabilidad
- Inventario
- PoS
- Project
- MRP
Se marcó esta pregunta
Hello Kai,
This is a formatting issue where Python requires you to have indentations when code is followed by a colon. This enables Python to know what is inside the condition and what is not, a lot of other languages don't require indentation but use it for readability as they have curly brackets "{}".
So changing your code to:
<record model="ir.actions.server" id="work_order_sequence">
<field name="name">Work Order Sequence Action</field>
<field name="model_id" ref="model_sale_order"/>
<field name="state">code</field>
<field name="code">
for record in records:
if record.order_type == "Workorder":
ref = env['ir.sequence'].next_by_code('work.order')
record['name'] = ref
</field>
</record>
Should hopefully fix your issue.
Thanks,
Hey Jack, you put me on the right track,
Few more modifications though (define the trigger field & Obs.: the curved brackets after the second colon!)
Here the final working code:
<record model="ir.actions.server" id="work_order_sequence">
<field name="name">Work Order Sequence Action</field>
<field name="model_id" ref="model_sale_order"/>
<field name="trigger">on_create</field>
<field name="state">code</field>
<field name="code">
for record in records:
if record.order_type == "Workorder":{}
ref = env['ir.sequence'].next_by_code('work.order')
record['name'] = ref
</field>
</record>
Thx
¿Le interesa esta conversación? ¡Participe en ella!
Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.
InscribirsePublicaciones relacionadas | Respuestas | Vistas | Actividad | |
---|---|---|---|---|
|
3
jun 20
|
5001 | ||
|
0
jun 20
|
2595 | ||
|
0
feb 16
|
3746 | ||
|
0
ago 23
|
3292 | ||
|
1
jul 23
|
2375 |