openerp 7: displaying Manufacturing Orders for Sales Order - odoo

I have created a custom entity that lets us select a sales order. The desire is that when a sales order is selected, it should show a list of manufacturing orders linked to that sales order.
How to go about getting this in place? And what should be in the mode? fields.related or fields.one2many?
Thanks
code:
class my_custom(osv.osv):
_name = 'mrp.mycustom'
_columns={
'name': fields.char('Name',size=64),
'salesorder_id': fields.many2one('sale.order','Sales Order')
}
my_custom()

There is no direct link between sale order and manufacturing order. You need to add a link first.then you you can use a one2many to show your manufacturing order

Related

Merge sale order line in Odoo programmatically

How can I merge sale order line on a sale order in Odoo programmatically? I have duplicated products in sale order line, I want to remove the duplicated lines but merge the quantity.
Thank you
The best way would be to deal with it at the origin: on sale order line creation : update quantity of an existing line having the same product instead of creating a new sale order line:
class SaleOrderLine(models.Model):
_inherit= 'sale.order.line'
#api.model_create_multi
def create(self, vals_list):
vals_list_newproduct=[]
for values in vals_list:
# if one order line contains a product already existing in this order:
existing_product_soline = self.search(
[('order_id','=',values['order_id'],('product_id','=',values['product_id'])])
if existing_product_soline:
existing_product_soline[0].write({
'product_uom_qty':
float(existing_product_soline[0]['product_uom_qty']) + float(values['product_uom_qty'])
})
else:
#this order line contains a new product for the sale order
vals_list_newproduct.append(values)
#create one new order_line as usual for lines containing new products
super(SaleOrderLine, self).create(vals_list_newproduct)

Odoo-14: How to add orderline in current POS order

I need to append a "specific" product in current order's orderline on the the click on particular button, same functionality needs to be used i.e. when you click on any product and it gets added to orderline. With following line of code, unable to get order id:
this.env.pos.get_order()
I am unable to get in-process order id as it is not yet created in backend until its paid.
To get the order and add a new orderline you can use
var order = this.env.pos.get_order();
order.add_product(product, { quantity: 1, price: total_price });

Odoo Show mobile on customer search

Using Odoo 10 - When creating a Sales Order or Invoice. When you search a customer it only shows the customer name. The problem is if you have two customers who's name is John Smith how do you know which one to select. If it could show mobile number also this would solve that problem.
Not sure where to edit code to show mobile number
You can modify override name_get function to get this result.
#api.multi
#api.depends('name', 'phone')
def name_get(self):
result = []
for customer in self:
name = customer.name + ' ' + customer.phone
result.append((customer.id, name))
return result
you can add your custom field(Char). Where you can concrete customer name and mobile no. After that you make this custom field rec_name by name_get method. This will help you.

Odoo - field from sales order to purchase order

I am using Odoo 10. I have a custom field call linear_units in Sales Order. I have make to order ticked and it creates an automatic Purchase order. I would like to include the field linear_units from Sales order to the purchase order. With below code I can select the Sales order but I cant figure out how to add a field.
class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
sale_order_id = fields.Many2one(
'sale.order',
"Sale Order",
help="Reference to Sale Order")
The above code works for selecting a sales order in purchase order. I have a float field in Sales order called linear_units. I need this field to copy to purchase order. I tried below but does not work
class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
linear_units2 = fields.Float("Linear Units")
#api.onchange('product_id','linear_units')
def _onchange_product_qty(self):
if self.product_id:
self.linear_units2 = self.sale.order.linear_units
you can add a related field in the purchase order for linear_units like below
class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
sale_order_id = fields.Many2one('sale.order', "Sale Order", help="Reference to Sale Order")
linear_units = fields.Float(related='sale_order_id.linear_units')
It will fetch the related linear_units value from the selected sale_order_id
hope this helps!
What is the purpose of this field. Is it supposed to be on each order line or is it supposed to be on the sale order as a whole. With the setup you have, you two options: First
sale_order_lines = fields.One2many('sale.order.line', 'Sale Order Lines')
Then from there you can reference your order number and your linear units.
sale_order_id = fields.Many2one('sale.order', related='sale_order_lines.order_id', string='Sale Order')
linear_units2 = fields.Float(related='sale_order_lines.linear_units', string='Linear Units')
and Second:
sale_order_id = fields.Many2one('sale.order', string='Sale Order')
linear_units = fields.Float(related='sale_order_id.sale_order_lines.linear_units', string='Linear units')
Though I'm not entirely certain that the second option will work. If this is the same value on all order lines then I would suggest putting linear_units on sale.order, then if you need it on the order lines you can put a related field on the order lines and then your fields will look like below
class SaleOrder(model.Models):
_inherit='sale.order'
linear_units = fields.Float(string='Linear Units')
class SaleOrderLines(model.Models):
_inherit='sale.order.lines'
linear_units = fields.Float(related='order_id.linear_units', string='Linear Units', readonly=True)
class PurchaseOrder(models.Models):
_inherit='purchase.order'
sale_order_id = fields.Many2one('sale.order', string='Sale Order')
linear_units = fields.Float(related='sale_order_id.linear_units', string='Linear Units', readonly=True)
(I suggest putting the read only on your related fields because if they are changed on your inherited view it will change it for that sale order and all of its relations.)

Odoo- How load products with multiple parents

I am working on Odoo 10e . I have situation which i am unable to solve in here.
I have a relation like following
Customer 1-------* Shipments 1-------* Shipment Detail 1-----* Products
Now i have a separate form in which i want to show products which are associated against a specific Customer in dropdown . How can i do this in Odoo
Do you mean you want to sort all products that have related to the Customer who selected in form view?
You can do this way:
#api.depends('customer')
def get_related_product(self):
res = []
#compute to get your product id here
return res
customer = fields.Many2one(....)
related_product = fields.Many2many(......., compute='get_related_product')