Skip to Content
Menu
This question has been flagged

I'm totally a newbie here who love Odoo so much :)

I got stuck with this problem for a few days in Odoo CE 13.

I want my SHIPPING TYPE field which I made in sale.order can be used in purchase.order as well.

So I did this in shipping_type.py

# -*- coding: utf-8 -*-
from odoo import models, fields

class SaleOrder(models.Model):
_inherit = 'sale.order'

shipping_selection = [
('type1', 'Instant'),
('type2', 'Same Day'),
('type3', 'JNE'),
('type4', 'Tokopedia'),
('type5', 'Pick Up'),
('type6', 'AnterAja-Reguler'),
('type7', 'J&T-Reguler'),
('type8', 'Ninja-Reguler'),

]

shipping_type = fields.Selection(shipping_selection,'Shipping Type',)

Then, I was trying to make purchase_shipping_type.py in another addons, and created this:

# -*- coding: utf-8 -*-
from odoo import models, fields


class SaleOrder(models.Model):
_inherit = ['sale.order'] shipping_selection = [
('type1', 'Instant'),
('type2', 'Same Day'),
('type3', 'JNE'),
('type4', 'Tokopedia'),
('type5', 'Pick Up'),
('type6', 'AnterAja-Reguler'),
('type7', 'J&T-Reguler'),
('type8', 'Ninja-Reguler'), ] shipping_type = fields.Selection(shipping_selection,'Shipping Type',)
class PurchaseOrder(models.Model):
_inherit = ['purchase.order']
shipping_type_purchase = fields.Selection(string='ShippingType',related=shipping_type.shipping_type_purhase, readonly=True)

This error showed up:

Aug 21 06:29:03 kama-odoo-server odoo13[24202]: NameError: name 'shipping_type' is not defined - - -

How to set up this properly? I really hope someone can help me :) Thanks!


Avatar
Discard
Author

@Niyas Raphy Sorry I don't have enough karma to comment on your answer. Thanks for providing the link, it's very useful. Basically, I just wanted to access the selection field (shipping_type in sales.order) and use it in purchase.order. What is the simplest solution for that?

I could see one line in the video:

patient_id = fields.Many2one('hospital.patient', string='Patient', required=True)

Is it possible if I use it like this:

shipping_type_purchase = fields.Selection('sale.order', string='ShippingType', required=True)

Best Answer

Hi,

It seems you have given the shipping_type_purchase as a related field, do you have a field name shipping_type in the purchase.order model ? i think its not there, that's why you are getting this error.

See how the related field in odoo works: How To Add Related Fields in Odoo


Thanks

Avatar
Discard
Related Posts Replies Views Activity
1
Jan 22
1978
1
Nov 24
1615
2
Apr 23
14534
1
Mar 23
1137
4
Aug 24
21119