|
@ -1,9 +1,10 @@ |
|
|
|
|
|
import logging |
|
|
import uuid |
|
|
import uuid |
|
|
|
|
|
|
|
|
from odoo import api, fields, models |
|
|
from odoo import api, fields, models |
|
|
from odoo.exceptions import UserError, ValidationError |
|
|
from odoo.exceptions import UserError, ValidationError |
|
|
from odoo.tools.translate import _ |
|
|
from odoo.tools.translate import _ |
|
|
import logging |
|
|
|
|
|
|
|
|
|
|
|
_logger = logging.getLogger(__name__) |
|
|
_logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -99,8 +100,9 @@ class BeesdooProduct(models.Model): |
|
|
else: |
|
|
else: |
|
|
return suppliers |
|
|
return suppliers |
|
|
|
|
|
|
|
|
@api.one |
|
|
|
|
|
|
|
|
@api.multi |
|
|
def generate_barcode(self): |
|
|
def generate_barcode(self): |
|
|
|
|
|
self.ensure_one() |
|
|
if self.to_weight: |
|
|
if self.to_weight: |
|
|
seq_internal_code = self.env.ref( |
|
|
seq_internal_code = self.env.ref( |
|
|
"beesdoo_product.seq_ean_product_internal_ref" |
|
|
"beesdoo_product.seq_ean_product_internal_ref" |
|
@ -145,16 +147,17 @@ class BeesdooProduct(models.Model): |
|
|
_logger.info("barcode :", bc) |
|
|
_logger.info("barcode :", bc) |
|
|
self.barcode = bc |
|
|
self.barcode = bc |
|
|
|
|
|
|
|
|
@api.one |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.depends("seller_ids", "seller_ids.date_start") |
|
|
@api.depends("seller_ids", "seller_ids.date_start") |
|
|
def _compute_main_seller_id(self): |
|
|
def _compute_main_seller_id(self): |
|
|
|
|
|
self.ensure_one() |
|
|
# Calcule le vendeur associé qui a la date de début la plus récente et plus petite qu’aujourd’hui |
|
|
# Calcule le vendeur associé qui a la date de début la plus récente et plus petite qu’aujourd’hui |
|
|
sellers_ids = ( |
|
|
sellers_ids = ( |
|
|
self._get_main_supplier_info() |
|
|
self._get_main_supplier_info() |
|
|
) # self.seller_ids.sorted(key=lambda seller: seller.date_start, reverse=True) |
|
|
) # self.seller_ids.sorted(key=lambda seller: seller.date_start, reverse=True) |
|
|
self.main_seller_id = sellers_ids and sellers_ids[0].name or False |
|
|
self.main_seller_id = sellers_ids and sellers_ids[0].name or False |
|
|
|
|
|
|
|
|
@api.one |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.depends( |
|
|
@api.depends( |
|
|
"taxes_id", |
|
|
"taxes_id", |
|
|
"list_price", |
|
|
"list_price", |
|
@ -164,6 +167,7 @@ class BeesdooProduct(models.Model): |
|
|
"weight", |
|
|
"weight", |
|
|
) |
|
|
) |
|
|
def _compute_total(self): |
|
|
def _compute_total(self): |
|
|
|
|
|
self.ensure_one() |
|
|
consignes_group = self.env.ref( |
|
|
consignes_group = self.env.ref( |
|
|
"beesdoo_product.consignes_group_tax", raise_if_not_found=False |
|
|
"beesdoo_product.consignes_group_tax", raise_if_not_found=False |
|
|
) |
|
|
) |
|
@ -209,27 +213,31 @@ class BeesdooProduct(models.Model): |
|
|
if self.display_weight > 0: |
|
|
if self.display_weight > 0: |
|
|
self.total_with_vat_by_unit = self.total_with_vat / self.weight |
|
|
self.total_with_vat_by_unit = self.total_with_vat / self.weight |
|
|
|
|
|
|
|
|
@api.one |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.depends("weight", "display_unit") |
|
|
@api.depends("weight", "display_unit") |
|
|
def _compute_display_weight(self): |
|
|
def _compute_display_weight(self): |
|
|
|
|
|
self.ensure_one() |
|
|
self.display_weight = self.weight * self.display_unit.factor |
|
|
self.display_weight = self.weight * self.display_unit.factor |
|
|
|
|
|
|
|
|
@api.one |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.constrains("display_unit", "default_reference_unit") |
|
|
@api.constrains("display_unit", "default_reference_unit") |
|
|
def _unit_same_category(self): |
|
|
def _unit_same_category(self): |
|
|
|
|
|
for product in self: |
|
|
if ( |
|
|
if ( |
|
|
self.display_unit.category_id |
|
|
|
|
|
!= self.default_reference_unit.category_id |
|
|
|
|
|
|
|
|
product.display_unit.category_id |
|
|
|
|
|
!= product.default_reference_unit.category_id |
|
|
): |
|
|
): |
|
|
raise UserError( |
|
|
raise UserError( |
|
|
_( |
|
|
_( |
|
|
"Reference Unit and Display Unit should belong to the same category" |
|
|
|
|
|
|
|
|
"Reference Unit and Display Unit should belong to the " |
|
|
|
|
|
"same category " |
|
|
) |
|
|
) |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
@api.one |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.depends("seller_ids") |
|
|
@api.depends("seller_ids") |
|
|
def _compute_cost(self): |
|
|
def _compute_cost(self): |
|
|
|
|
|
self.ensure_one() |
|
|
suppliers = self._get_main_supplier_info() |
|
|
suppliers = self._get_main_supplier_info() |
|
|
if len(suppliers) > 0: |
|
|
if len(suppliers) > 0: |
|
|
self.suggested_price = ( |
|
|
self.suggested_price = ( |
|
@ -275,10 +283,11 @@ class BeesdooProductCategory(models.Model): |
|
|
|
|
|
|
|
|
profit_margin = fields.Float(default="10.0", string="Product Margin [%]") |
|
|
profit_margin = fields.Float(default="10.0", string="Product Margin [%]") |
|
|
|
|
|
|
|
|
@api.one |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.constrains("profit_margin") |
|
|
@api.constrains("profit_margin") |
|
|
def _check_margin(self): |
|
|
def _check_margin(self): |
|
|
if self.profit_margin < 0.0: |
|
|
|
|
|
|
|
|
for product in self: |
|
|
|
|
|
if product.profit_margin < 0.0: |
|
|
raise UserError(_("Percentages for Profit Margin must > 0.")) |
|
|
raise UserError(_("Percentages for Profit Margin must > 0.")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|