diff --git a/README.md b/README.md index 0512b005c6daa795827f2ccaa8e3ef947965f7bb..42f30ee6e6ae3d88b12a5b9700c5fb445421a354 100644 --- a/README.md +++ b/README.md @@ -18,13 +18,13 @@ Script pour la mise-à -jour des données odoo à partir du fichier biopartner. ``` * Télécharger le code ```console - TARGET=/usr/lib/bio_partner/ + TARGET=~/.local/bio_partner/ mkdir -p $TARGET cd $TARGET git clone https://gitlab.inubo.ch/marco.defreitas/le_nid/ . * Créer un virtual env ```console - python3 -m virtualenv -p /usr/bin/python3 ./venv + python3 -m virtualenv -p /usr/bin/python3.8 ./venv source ./venv/bin/activate pip3 install -r requirements.txt ``` diff --git a/biopartner_to_odoo/__init__.py b/biopartner_to_odoo/__init__.py index adebc2faa0a24058ea65d9797bc5d43f31a280bc..143da7967ac41d0da0c581d0c30e334d3d7f54ec 100644 --- a/biopartner_to_odoo/__init__.py +++ b/biopartner_to_odoo/__init__.py @@ -25,6 +25,8 @@ TYPE_TAX_USE = "type_tax_use" DEFAULT_SERVER_DATE_FORMAT = "%Y-%m-%d" UOM_ID = "uom_id" UOM_PO_ID = "uom_po_id" +PURCHASE_OK = "purchase_ok" +SALE_OK = "sale_ok" PRODUCT_FIELD_LIST = [ PRODUCT_ID, @@ -42,4 +44,6 @@ PRODUCT_FIELD_LIST = [ STANDARD_PRICE, UOM_ID, UOM_PO_ID, + PURCHASE_OK, + SALE_OK ] diff --git a/biopartner_to_odoo/__main__.py b/biopartner_to_odoo/__main__.py index c034c58bec988270ad7344ae8b339ddb43f2437c..d8a47eedc7509de5713dca71675b676073d4c45a 100755 --- a/biopartner_to_odoo/__main__.py +++ b/biopartner_to_odoo/__main__.py @@ -57,8 +57,10 @@ def update_products(biopartner_files, odoo_url, odoo_db, odoo_user, if any(s.name == supplier_name for s in product.suppliers_info): if not (ean in products_updated_by_biopartner): nb_fix_required += 1 - logging.warning(f"{odoo_products[ean]}" - f" does not exist in the XLXS file.") + if nb_fix_required == 1: + logging.warning(f"Product(s) not found in Biopartner:") + logging.warning('=' * 146) + logging.warning(odoo_products[ean]) if nb_fix_required > 0: print(f"\nThere {'are' if nb_fix_required > 1 else 'is'} " @@ -193,7 +195,7 @@ def drop_supplier_info(odoo_url, odoo_db, odoo_user, odoo_password, # Summary of products to be updated. print(f"List of products with at least one incomplete supplier info " - f"item.\n{'='*169}") + f"item.\n{'=' * 169}") update_summary_report(target_products, n=30) # Confirm the deletion of supplier info items. diff --git a/biopartner_to_odoo/odoo.py b/biopartner_to_odoo/odoo.py index aa9ce7061013a3d2481d18dc2891cb89b43a37fb..522726c4344396be8c93a36ffed2ee62ec7855f3 100644 --- a/biopartner_to_odoo/odoo.py +++ b/biopartner_to_odoo/odoo.py @@ -50,7 +50,7 @@ def fetch_odoo_products_with_barcode( uid = get_odoo_uid(db, password, url, username) models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url)) - parameters = {'fields': PRODUCT_FIELD_LIST} + parameters = {'fields': PRODUCT_FIELD_LIST, 'context': {'lang': u"fr_CH"}} object_name = 'product.product' domain = [[ [BARCODE, "!=", False]] @@ -60,7 +60,8 @@ def fetch_odoo_products_with_barcode( suppliers=suppliers, taxes=taxes, uoms=uoms, - current_date=current_date) + current_date=current_date, + odoo_url=url) for product in models.execute_kw( db, uid, password, object_name, 'search_read', domain, parameters) } diff --git a/biopartner_to_odoo/product.py b/biopartner_to_odoo/product.py index aa64c998625cee39a4e733a4cf8075bdc0513224..20dbb4244f5c521f59bb954cab27f77fc044542a 100644 --- a/biopartner_to_odoo/product.py +++ b/biopartner_to_odoo/product.py @@ -13,8 +13,11 @@ from biopartner_to_odoo.supplier_info import SupplierInfo class Product(object): - def __init__(self, suppliers, taxes, uoms=None, current_date=None, **kwargs): + def __init__(self, suppliers, taxes, uoms=None, current_date=None, + odoo_url=None, **kwargs): + self._current_date = current_date + self.odoo_url = odoo_url self.uom = None self.po_uom = None self.list_price_change = None @@ -27,6 +30,8 @@ class Product(object): self.active = kwargs["active"] self.name = kwargs["name"] self.barcode = kwargs["barcode"] + self.purchase_ok = kwargs["purchase_ok"] + self.sale_ok = kwargs["sale_ok"] self.taxes = [taxes[tid] for tid in kwargs["taxes_id"] if tid in taxes] self.suppliers_info: List[SupplierInfo] = \ [SupplierInfo(product=self, **suppliers[sid]) @@ -59,11 +64,16 @@ class Product(object): return self.name < other.name def __repr__(self): - return (f"<Product: {repr(self.name)[:33]:<35} " - f"sell price = {self.list_price:7.2f} " - f"barcode = {self.barcode:<13} " - f"internal reference = {repr(self.default_code):<7} " - f"with {len(self.suppliers_info)} supplier lines>") + product_name = str(self.name) + "," + if len(product_name) > 50: + product_name = product_name[:47] + "..." + + return (f"<Product: {product_name:<51} " + f"sell price = {self.list_price:7.2f}, " + f"barcode = {self.barcode:<13}, " + f"sale = {'yes' if self.sale_ok else 'no '}, " + f"purchase = {'yes' if self.purchase_ok else 'no '}, " + f"{self.link}>") @classmethod def from_biopartner_row(cls, row, taxes, date, odoo_supplier_name): @@ -91,6 +101,8 @@ class Product(object): REORDERING_MIN_QTY: None, TAXES_ID: cls.parse_vat(row[biopartner.VAT_INDEX], taxes), SELLER_IDS: [-1], + PURCHASE_OK: True, + SALE_OK: True, BARCODE: str(row[biopartner.EAN_INDEX]) } return cls(suppliers=supplier_info, taxes=taxes, **biopartner_product) @@ -105,6 +117,13 @@ class Product(object): def parse_to_weight_bool(unit): return unit.strip().lower() == biopartner.KG + @property + def link(self): + text = f"odoo url" + url = f"{self.odoo_url}/web#id={self.product_id}&action=124" \ + f"&model=product.product" + return f"\u001b]8;;{url}\u001b\\{text}\u001b]8;;\u001b\\" + @property def current_date(self): if self._current_date is not None: diff --git a/biopartner_to_odoo/utils.py b/biopartner_to_odoo/utils.py index 8127b58d61b811e31dddcc99b4985a74ecfd01f7..e4abfae53484aef0f67cb82435735eadceff9d24 100644 --- a/biopartner_to_odoo/utils.py +++ b/biopartner_to_odoo/utils.py @@ -1,6 +1,7 @@ import argparse import datetime import itertools +import logging import os from urllib.parse import urlparse @@ -32,7 +33,6 @@ def parse_cli_args(): parser.add_argument('--log', type=str, default="INFO") parser.add_argument('--batchsize', type=int, default=5) parser.add_argument('--path', type=file_path, nargs='*') - parser.add_argument('--date', type=date_validator) parser_suppliers.add_argument('--path', type=file_path, nargs='*') parser_price.add_argument('--date', type=date_validator) @@ -97,6 +97,8 @@ def file_path(string): def uri_validator(uri): result = urlparse(uri) _ = all([result.scheme, result.netloc, result.path]) + if uri.endswith("/"): + return uri[:-1] return uri @@ -104,7 +106,7 @@ def date_validator(date_string): return datetime.datetime.strptime(date_string, "%Y-%m-%d").date() -def show_info_text(n=169): +def show_info_text(n=171): info_text = f"Showing all products with change in price, min quantity, " \ f"product name, validity date, or tax. Products are sorted " \ f"from highest price change to lowest price change.".ljust(n) diff --git a/run.py b/run.py index e9b4e0d2cfc7ca065ae1b010ad8b647426851754..4d829399c614e39ab5b85f4baa2276997c4cadd2 100755 --- a/run.py +++ b/run.py @@ -1,4 +1,4 @@ -#!/usr/lib/bio_partner/venv/bin/python +#!~/.local/bio_partner/venv/bin/python from biopartner_to_odoo.__main__ import main