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
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
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
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
3
Jun 20
|
3816 | ||
|
0
Jun 20
|
1750 | ||
|
0
Feb 16
|
2850 | ||
|
0
Aug 23
|
1832 | ||
|
1
Jul 23
|
1298 |