Browse Source

[REF] @api.one -> @api.multi

pull/142/head
robin.keunen 4 years ago
parent
commit
e782462c5a
  1. 9
      beesdoo_base/wizard/member_card.py
  2. 3
      beesdoo_base/wizard/partner.py
  3. 3
      beesdoo_easy_my_coop/models/coop.py
  4. 45
      beesdoo_product/models/beesdoo_product.py
  5. 6
      beesdoo_product/wizard/label_printing_utils.py

9
beesdoo_base/wizard/member_card.py

@ -20,8 +20,9 @@ class NewMemberCardWizard(models.TransientModel):
"Force Barcode", groups="beesdoo_base.group_force_barcode" "Force Barcode", groups="beesdoo_base.group_force_barcode"
) )
@api.one
@api.multi
def create_new_card(self): def create_new_card(self):
self.ensure_one()
client = self.partner_id.sudo() client = self.partner_id.sudo()
client._deactivate_active_cards() client._deactivate_active_cards()
client._new_card( client._new_card(
@ -41,8 +42,9 @@ class RequestMemberCardPrintingWizard(models.TransientModel):
"res.partner", default=_get_selected_partners "res.partner", default=_get_selected_partners
) )
@api.one
@api.multi
def request_printing(self): def request_printing(self):
self.ensure_one()
self.partner_ids.write({"member_card_to_be_printed": True}) self.partner_ids.write({"member_card_to_be_printed": True})
@ -57,8 +59,9 @@ class SetAsPrintedWizard(models.TransientModel):
"res.partner", default=_get_selected_partners "res.partner", default=_get_selected_partners
) )
@api.one
@api.multi
def set_as_printed(self): def set_as_printed(self):
self.ensure_one()
self.partner_ids.write( self.partner_ids.write(
{ {
"member_card_to_be_printed": False, "member_card_to_be_printed": False,

3
beesdoo_base/wizard/partner.py

@ -18,6 +18,7 @@ class NewEaterWizard(models.TransientModel):
partner_id = fields.Many2one("res.partner", default=_get_default_partner) partner_id = fields.Many2one("res.partner", default=_get_default_partner)
@api.one
@api.multi
def create_new_eater(self): def create_new_eater(self):
self.ensure_one()
self.partner_id._new_eater(self.first_name, self.last_name, self.email) self.partner_id._new_eater(self.first_name, self.last_name, self.email)

3
beesdoo_easy_my_coop/models/coop.py

@ -17,8 +17,9 @@ class SubscriptionRequest(models.Model):
return vals return vals
@api.one
@api.multi
def validate_subscription_request(self): def validate_subscription_request(self):
self.ensure_one()
invoice = super( invoice = super(
SubscriptionRequest, self SubscriptionRequest, self

45
beesdoo_product/models/beesdoo_product.py

@ -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):
if (
self.display_unit.category_id
!= self.default_reference_unit.category_id
):
raise UserError(
_(
"Reference Unit and Display Unit should belong to the same category"
for product in self:
if (
product.display_unit.category_id
!= product.default_reference_unit.category_id
):
raise UserError(
_(
"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,11 +283,12 @@ 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:
raise UserError(_("Percentages for Profit Margin must > 0."))
for product in self:
if product.profit_margin < 0.0:
raise UserError(_("Percentages for Profit Margin must > 0."))
class BeesdooProductSupplierInfo(models.Model): class BeesdooProductSupplierInfo(models.Model):

6
beesdoo_product/wizard/label_printing_utils.py

@ -12,12 +12,14 @@ class RequestLabelPrintingWizard(models.TransientModel):
"product.template", default=_get_selected_products "product.template", default=_get_selected_products
) )
@api.one
@api.multi
def request_printing(self): def request_printing(self):
self.ensure_one()
self.product_ids.write({"label_to_be_printed": True}) self.product_ids.write({"label_to_be_printed": True})
@api.one
@api.multi
def set_as_printed(self): def set_as_printed(self):
self.ensure_one()
self.product_ids.write( self.product_ids.write(
{ {
"label_to_be_printed": False, "label_to_be_printed": False,

Loading…
Cancel
Save