Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

how to resolve errorhow to resolve this error " 'product.template' has no attribute 'generate_ean13' ??

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
python2.7odooV9
1 Répondre
10250 Vues
Avatar
Dhouha

i'm using  odoo 9 and i have created a custom module for product barcode generation. Everytime when i press the button 'generate the ean13 ' this error shows and i don't know what to do .

Any help please this is my code 

_______________________________________________________________________________________________

product_view.xml 

<?xml version="1.0" encoding="utf-8"?>

<odoo>


        <record id="view_product_category_simple_ean_form" model="ir.ui.view">

            <field name="name">product.category.form</field>

            <field name="model">product.category</field>

            <field name="inherit_id" ref="product.product_category_form_view" />

            <field name="arch" type="xml">

                <field name="type" position="after">

                    <field name="ean_sequence_id" domain="[('barcode_sequence', '=', 1)]"

                        context="{'default_name': name and 'EAN ' + name or 'EAN', 'default_barcode_sequence': 1}" />

                    <newline />

                </field>

            </field>

        </record>


        <record id="view_product_simple_ean_form" model="ir.ui.view">

            <field name="name">product.template.product.form.barcode</field>

            <field name="model">product.template</field>

            <field name="inherit_id" ref="product.product_template_only_form_view" />

            <field name="arch" type="xml">

              

                <field name="barcode" position="after">

                  

                    <button string="Generate the EAN13" name="generate_ean13"

                        attrs="{'invisible': [('barcode', '!=', False)]}"

                        type="object" colspan="2" />

                </field>

            </field>

        </record>

</odoo>

__________________________________________________________________________________________

product.py 

<?xml version="1.0" encoding="utf-8"?>

<odoo>


        <record id="view_product_category_simple_ean_form" model="ir.ui.view">

            <field name="name">product.category.form</field>

            <field name="model">product.category</field>

            <field name="inherit_id" ref="product.product_category_form_view" />

            <field name="arch" type="xml">

                <field name="type" position="after">

                    <field name="ean_sequence_id" domain="[('barcode_sequence', '=', 1)]"

                        context="{'default_name': name and 'EAN ' + name or 'EAN', 'default_barcode_sequence': 1}" />

                    <newline />

                </field>

            </field>

        </record>


        <record id="view_product_simple_ean_form" model="ir.ui.view">

            <field name="name">product.template.product.form.barcode</field>

            <field name="model">product.template</field>

            <field name="inherit_id" ref="product.product_template_only_form_view" />

            <field name="arch" type="xml">

              

                <field name="barcode" position="after">

                  

                    <button string="Generate the EAN13" name="generate_ean13"

                        attrs="{'invisible': [('barcode', '!=', False)]}"

                        type="object" colspan="2" />

                </field>

            </field>

        </record>

</odoo>



0
Avatar
Ignorer
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Meilleure réponse

Hi,

Going through the given code along with the question, it seems you have added a new button to the product.template model.


You have to add the function generate_ean13 to the same model.  Right now as there is no such a function in the same model you are getting this error when you click the newly added button.

class ProductTemplate(models.Model):
_inherit = "product.template"

@api.multi
def generate_ean13(self):
# code here


Also, you can have a look at the Product Barcode Generator module available in the v10 : https://www.odoo.com/apps/modules/10.0/product_barcode/


Thanks

4
Avatar
Ignorer
Dhouha
Auteur

199/5000

I did not notice that it pasted the product_view.xml code into product.py. my problem that I already wrote the function generate_ean13 but he did not take it into consideration here is my code

from openerp import api, models, fields, _

from openerp import exceptions

def isodd(x):

return bool(x % 2)

class ProductCategory(models.Model):

_inherit = 'product.category'

ean_sequence_id = fields.Many2one('ir.sequence', string='Ean sequence')

class ProductTemplate(models.Model):

_inherit = 'product.template'

barcode = fields.Char(copy=False)

ean= fields.Char(copy=False)

_columns = {

ean_sequence_id : fields.Many2one('ir.sequence', string='Ean sequence')

}

@api.model

def _get_ean_next_code(self, product):

sequence_obj = self.env['ir.sequence']

if product.ean_sequence_id:

ean = sequence_obj.next_by_id(product.ean_sequence_id.id)

elif product.categ_id.ean_sequence_id:

ean = sequence_obj.next_by_id(product.categ_id.ean_sequence_id.id)

elif product.company_id and product.company_id.ean_sequence_id:

ean = sequence_obj.next_by_id(

product.company_id.ean_sequence_id.id)

elif self.env.context.get('sequence_id', False):

ean = sequence_obj.next_by_id(self.env.context.get('sequence_id'))

else:

return None

ean = (len(ean[0:6]) == 6 and ean[0:6] or

ean[0:6].ljust(6, '0')) + ean[6:].rjust(6, '0')

if len(ean) > 12:

raise exceptions.Warning(

_("Configuration Error!"

"The next sequence is longer than 12 characters. "

"It is not valid for an EAN13 needing 12 characters, "

"the 13 being used as a control digit"

"You will have to redefine the sequence or create a new one")

)

return ean

def _get_ean_control_digit(self, code):

sum = 0

for i in range(12):

if isodd(i):

sum += 3 * int(code[i])

else:

sum += int(code[i])

key = (10 - sum % 10) % 10

return '%d' % key

@api.model

def _generate_ean13_value(self, product):

ean = self._get_ean_next_code(product)

if not ean:

return None

key = self._get_ean_control_digit(ean)

barcode = ean + key

return barcode

@api.one

def generate_ean13(self):

if not self.barcode:

barcode = self._generate_ean13_value(self)

if barcode:

self.write({'barcode': barcode})

return True

Cybrosys Techno Solutions Pvt.Ltd

Then check whether this py file is called in the init file

Dhouha
Auteur

he is called in the init file "from . import product" that's why i'm i'm desprerate because i have tried every thing but i still don't know why this error shows up

Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
How to add fixed tax automatically in invoice
python2.7 odooV9
Avatar
Avatar
Avatar
2
juil. 22
6667
how to create a access rule to limit product creation for sale managers?
python2.7 odooV9
Avatar
Avatar
Avatar
2
juil. 21
7066
How can I setup Tax so that I can charge on the TOTAL Invoice amount, then on the Products, then a Stamp Tax.
python2.7 odooV9
Avatar
0
juil. 18
3521
AttributeError: 'int' object has no attribute 'id' on odoo 9
python2.7 odooV9
Avatar
Avatar
1
juil. 17
11251
create a notification on odoo v9 Résolu
python2.7 odooV9
Avatar
Avatar
1
juil. 17
3911
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now