from odoo import models, fields, apifrom odoo.exceptions import UserError, Warning
class ImportCatalogueLine(models.Model): _name = 'import.catalogue.line' _description = "Ligne d'importation du catalogue"
collection_char = fields.Char(string="Collection") brand = fields.Char(string="Marque") model = fields.Char(string='Modèle') import_catalogue_id = fields.Many2one(comodel_name='import.catalogue', string='Import catalogue') imported = fields.Boolean(string='Importé', default=False) updated = fields.Boolean(string='Mise à jour', default=False)
def get_product(self): product_tmpl = self.env['product.template'].search([('default_code', '=', self.model)]) if not product_tmpl: product_id = self.env['product.template'].create({ 'name': self.model, 'sale_ok': True, 'purchase_ok': True, 'vdl_check': True, 'type': 'product', }) product_tmpl = product_id elif len(product_tmpl) == 1: product_tmpl = product_tmpl[0] else: raise Warning(f"Le modèle {self.model} existe déjà en plusieurs exemplaiproduct_tmpl, veuillez corriger") return product_tmpl
class ImportCatalogue(models.Model): _name = 'import.catalogue' _description = 'import_catalogue_line'
date_import = fields.Date('Date import') import_catalogue_line_ids = fields.One2many(comodel_name='import.catalogue.line', inverse_name='import_catalogue_id', string='Ligne import catalogue')
kanban_state = fields.Selection([('draft', 'Brouillon'), ('imported', 'Collecte des données à importer'), ('update', 'Mise à jour'), ('done', 'Terminé'), ('deleted', 'Nettoyé'), ], string='Etats', readonly=True, copy=False, index=True, default='draft', ) nb_line_updated = fields.Integer(string='Nb de lignes misent à jour', default=0, readonly=True) batch = fields.Integer(string='Taille de batch', default=2000)
def unlink(self): for obj in self: for import_catalogue_line in obj.import_catalogue_line_ids: import_catalogue_line.unlink() return super(ImportCatalogue, self).unlink()
def delete_all(self): for import_catalogue in self.import_catalogue_line_ids.search([('updated', '=', True)], limit=self.batch): import_catalogue.unlink() self.kanban_state = 'deleted'
def collect_datas(self): import_catalogue_line_ids = self.env['import.catalogue.line'].search([('imported', '=', False)]) for import_catalogue_line in import_catalogue_line_ids: import_catalogue_line.import_catalogue_id = self.id import_catalogue_line.imported = True self.kanban_state = 'imported'
def create_product_in_catalog(self, product): catalog_product = self.env['vdl.product_catalog'].search([('name', '=', product.name)], limit=1) if not catalog_product: catalog_product = self.env['vdl.product_catalog'].create({ 'name': product.name, 'collection_char': product.collection_char, 'family': product.family, }) else: raise Warning(f"Prouduit avec le nom {product.name} existe déjà dans le catalogue.")
def update_datas(self): lines_to_update = self.import_catalogue_line_ids.search([('updated', '=', False)], limit=self.batch) for line in lines_to_update[:self.batch]: product = line.get_product() product.brand = line.brand product.collection_char = line.collection_char line.updated = True self.nb_line_updated += 1 self.create_product_in_catalog(product)
if len(lines_to_update) == self.nb_line_updated: self.kanban_state = 'done' else: self.kanban_state = 'update'
can someone fix my code?
i get in to trouble when i want to import data to catalog and product
so the flow is i want to import some data into catalog and product but first it get into catalog(vdl.product_catalog) and then into product(product.template). and if there are same data then it will not be processed but the different are.
but the problem that i faced is when it imported to catalog the same data is not processed but when it into the product it not processed. it should be taken the data when we imported into catalog to the product
hope u understand. sorry for my bad explanation im still junior at odoo and english
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Comptabilitat
- Inventari
- PoS
- Project
- MRP
This question has been flagged
S'ha tancat la pregunta per raó: Question / Code not indented
per Muhammad Ihza Putra Handayani en 28/06/2024 05:08:04
per Muhammad Ihza Putra Handayani en 28/06/2024 05:08:04
840
Vistes
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Registrar-seRelated Posts | Respostes | Vistes | Activitat | |
---|---|---|---|---|
import product with stock
Solved
|
|
4
de juny 24
|
13353 | |
|
8
de gen. 25
|
6968 | ||
|
3
de juny 24
|
9483 | ||
|
1
d’abr. 25
|
1610 | ||
|
2
d’abr. 24
|
2321 |