0

I am trying to delete the part number(default_code) from the description but I can't get it to work, is there a way to delete ir or hide it?

Quotation Report

1 Answers1

1

Hi and welcome to stackoverflow.

First, you can add show your image in your question, you don't need to reference in a link.

Second, you have to know that the exact line where the default_code is add to the product's name is in this line, and override it is not an option because it would affect the entire functionality of Odoo not just for reports.

Third, you are trying to modify the product's description but not the name, in this sense you have two option to solve your problem:

  1. Change the product's description manualy when you add a new line order line. Or
  2. To do automatically do the point 1. you need to override the function product_id_change that fill the order line when you select a product to remove the default_code surrounded for the brackets, to achieve that use the code below:

Update: add imports

    import re

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

        @api.multi
        @api.onchange('product_id')
        def product_id_change(self):
            #call the super to maintain the proper flow
            super(SaleOrderLine, self).product_id_change()
            if not self.product_id:
                return {'domain': {'product_uom': []}}
            else:
                vals = {}
                #if the super already assigned a name
                if self.name:
                    regex_pattern = r'\[\w+\] '
                    #count is the maximum number of pattern occurrences
                    rename = re.sub(regex_pattern, '', self.name, count=1, flags=re.IGNORECASE)
                    vals['name'] = rename
                    self.update(vals)

Now the report doesn't have [default_code]. You should take a look the original function for better understanding.

I hope this answer can be helpful for you.

Juan Salcedo
  • 1,598
  • 1
  • 16
  • 28
  • Thanks for answering I will check this and get back at you. Yeah I understad what the override can do. My associates are insisting on this, they want to eliminate the default_code from the description and even I asked if they can do it manually but they said that sometimes there are more than one product in a sales order line and I just don't want to eliminated from the system itself that would just make it worse because we use it for other process. – Zer0P3nalty Jul 09 '18 at 16:20
  • I checked the code, is giving error: re is not defined. So I guess you meant 'r' and not 're' right? – Zer0P3nalty Jul 09 '18 at 16:51
  • Just add the proper import for Regular Expresions called `re` something like this `import re` – Juan Salcedo Jul 10 '18 at 17:45
  • My mistake, after a few test, the module is giving Internal Server Error due to: File "/odoo/odoo-server/odoo/models.py", line 531, in _build_model raise TypeError("Model %r does not exist in registry." % name) – Zer0P3nalty Jul 11 '18 at 16:26
  • That error is because you are missing some dependencies in your `__manifest__.py` file, and it is another problem not related with my solution. – Juan Salcedo Jul 12 '18 at 00:31