Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Many2one relation not saving properly

By
Charles Gervais-Dumont
on 3/9/15, 12:59 PM 362 views

I've been working on a MRP system to handle parts and BOM for electronic manufacturing.

Each bomline is related to a part, but when I save the bomline in a bom, all the bomlines point to part #1. If I edit and save a bomline, the line gets deleted.

Here are the related classes:

Bom:

class bom(models.Model):

    _name = 'components.bom'
    _rec_name = 'resultingpart'

    lines = fields.One2many('components.bomline', 'partnumber', 'Items', ondelete='cascade')
    partcount = fields.Integer(compute='_compute_part_count', string="Part Count")
    resultingpart = fields.Many2one('components.part', 'Resulting Part', ondelete='no action')
    description = fields.Text()

    @api.one
    def _compute_part_count(self):
        self.partcount = 0

 

Bomline:

class bomline(models.Model):

    _name = 'components.bomline'

    name = fields.Char(string="Part Identifier", required=True)
    partnumber = fields.Many2one('components.part', string="Part Number", relation='line2part')
    description = fields.Text(string="Description", related='partnumber.description', readonly=True)

 

Part:

class part(models.Model):
    _name = 'components.part'
    _rec_name = 'part_number'

    part_id = fields.Integer(string="ID", required=True)
    part_number = fields.Char(compute='_compute_part_name', string="Part Number")
    description = fields.Text()
    part_type = fields.Many2one('components.part_type', 'Type', ondelete='no action')
    manufacturer_part = fields.Many2many('components.manufacturer_part', string="Manufacturer Part Number")

    @api.one
    def _compute_part_name(self):
        self.part_number = "GSS-P" + str(self.part_id).zfill(6)

    def getNext(self, cr, uid):
        recs = self.pool.get("components.part").search(cr, uid, [])
        if recs:
            next = 0
            for rec in recs:
                part_rec = self.browse(cr, uid, rec)
                next = max(next, part_rec.part_id)
            return next + 1
        else:
            return 1

    _defaults = {'part_id': lambda self, cr, uid, context: self.getNext(cr, uid),}
 

 

0

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
http://www.odoo.com
5975
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.

 

Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 

 

We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :

 

  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 3/10/15, 12:44 AM

Hi,

I think you were given wrong defination of the following field into bomline.

partnumber = fields.Many2one('components.part', string="Part Number", relation='line2part')

You have to remove relation from this field as like below.

partnumber = fields.Many2one('components.part', string="Part Number")

I hope it will resolve your issue.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/9/15, 12:59 PM
Seen: 362 times
Last updated: 3/16/15, 8:10 AM