Browse Source

[REF] Name of compute method should start with "_compute_"

pull/142/head
robin.keunen 5 years ago
parent
commit
62a3fe1e30
  1. 6
      beesdoo_base/models/partner.py
  2. 4
      beesdoo_easy_my_coop/models/res_partner.py
  3. 8
      beesdoo_easy_my_coop/tests/test_res_partner.py
  4. 20
      beesdoo_product/models/beesdoo_product.py
  5. 16
      beesdoo_shift/models/planning.py
  6. 13
      purchase_order_generator/models/purchase_order_generator.py

6
beesdoo_base/models/partner.py

@ -18,10 +18,10 @@ class Partner(models.Model):
"res.partner", string="Parent Worker", readonly=True
)
barcode = fields.Char(
compute="_get_bar_code", string="Barcode", store=True
compute="_compute_bar_code", string="Barcode", store=True
)
parent_barcode = fields.Char(
compute="_get_bar_code", string="Parent Barcode", store=True
compute="_compute_bar_code", string="Parent Barcode", store=True
)
member_card_ids = fields.One2many("member.card", "partner_id")
@ -34,7 +34,7 @@ class Partner(models.Model):
"eater",
"member_card_ids",
)
def _get_bar_code(self):
def _compute_bar_code(self):
for rec in self:
if rec.eater == "eater":
rec.parent_barcode = rec.parent_eater_id.barcode

4
beesdoo_easy_my_coop/models/res_partner.py

@ -12,7 +12,7 @@ class Partner(models.Model):
string="Confirmed presence to info session", default=False
)
is_worker = fields.Boolean(
compute="_is_worker",
compute="_compute_is_worker",
search="_search_worker",
readonly=True,
related="",
@ -38,7 +38,7 @@ class Partner(models.Model):
"share_ids.share_product_id.default_code",
"share_ids.share_number",
)
def _is_worker(self):
def _compute_is_worker(self):
"""
Return True if the partner can participate tho the shift system.
This is defined on the share type.

8
beesdoo_easy_my_coop/tests/test_res_partner.py

@ -129,7 +129,7 @@ class TestResPartner(TransactionCase):
"""
coop1 = self.env.ref("beesdoo_base.res_partner_cooperator_1_demo")
# Run computed field
coop1._is_worker()
coop1._compute_is_worker()
self.assertEqual(coop1.is_worker, True)
def test_is_worker_share_b(self):
@ -138,7 +138,7 @@ class TestResPartner(TransactionCase):
"""
coop2 = self.env.ref("beesdoo_base.res_partner_cooperator_2_demo")
# Run computed field
coop2._is_worker()
coop2._compute_is_worker()
self.assertEqual(coop2.is_worker, False)
def test_search_worker(self):
@ -149,8 +149,8 @@ class TestResPartner(TransactionCase):
coop1 = self.env.ref("beesdoo_base.res_partner_cooperator_1_demo")
coop2 = self.env.ref("beesdoo_base.res_partner_cooperator_2_demo")
# Run computed field
coop1._is_worker()
coop2._is_worker()
coop1._compute_is_worker()
coop2._compute_is_worker()
workers = self.env["res.partner"].search([("is_worker", "=", True)])
self.assertIn(coop1, workers)
self.assertNotIn(coop2, workers)

20
beesdoo_product/models/beesdoo_product.py

@ -30,18 +30,22 @@ class BeesdooProduct(models.Model):
display_unit = fields.Many2one("uom.uom")
default_reference_unit = fields.Many2one("uom.uom")
display_weight = fields.Float(compute="_get_display_weight", store=True)
display_weight = fields.Float(
compute="_compute_display_weight", store=True
)
total_with_vat = fields.Float(
compute="_get_total", store=True, string="Total Sales Price with VAT"
compute="_compute_total",
store=True,
string="Total Sales Price with VAT",
)
total_with_vat_by_unit = fields.Float(
compute="_get_total",
compute="_compute_total",
store=True,
string="Total Sales Price with VAT by Reference Unit",
)
total_deposit = fields.Float(
compute="_get_total", store=True, string="Deposit Price"
compute="_compute_total", store=True, string="Deposit Price"
)
label_to_be_printed = fields.Boolean("Print label?")
@ -63,7 +67,7 @@ class BeesdooProduct(models.Model):
scale_label_info_1 = fields.Char(string="Scale lable info 1")
scale_label_info_2 = fields.Char(string="Scale lable info 2")
scale_sale_unit = fields.Char(
compute="_get_scale_sale_uom", string="Scale sale unit", store=True
compute="_compute_scale_sale_uom", string="Scale sale unit", store=True
)
scale_category = fields.Many2one(
"beesdoo.scale.category", string="Scale Category"
@ -77,7 +81,7 @@ class BeesdooProduct(models.Model):
@api.depends("uom_id", "uom_id.category_id", "uom_id.category_id.type")
@api.multi
def _get_scale_sale_uom(self):
def _compute_scale_sale_uom(self):
for product in self:
if product.uom_id.category_id.type == "unit":
product.scale_sale_unit = "F"
@ -157,7 +161,7 @@ class BeesdooProduct(models.Model):
"display_weight",
"weight",
)
def _get_total(self):
def _compute_total(self):
consignes_group = self.env.ref(
"beesdoo_product.consignes_group_tax", raise_if_not_found=False
)
@ -205,7 +209,7 @@ class BeesdooProduct(models.Model):
@api.one
@api.depends("weight", "display_unit")
def _get_display_weight(self):
def _compute_display_weight(self):
self.display_weight = self.weight * self.display_unit.factor
@api.one

16
beesdoo_shift/models/planning.py

@ -120,18 +120,18 @@ class TaskTemplate(models.Model):
domain=[("is_worker", "=", True)],
)
remaining_worker = fields.Integer(
compute="_get_remaining", store=True, string="Remaining Place"
compute="_compute_remaining", store=True, string="Remaining Place"
)
active = fields.Boolean(default=True)
# For Kanban View Only
color = fields.Integer("Color Index")
worker_name = fields.Char(compute="_get_worker_name")
worker_name = fields.Char(compute="_compute_worker_name")
# For calendar View
start_date = fields.Datetime(
compute="_get_fake_date", search="_dummy_search"
compute="_compute_fake_date", search="_search_dummy"
)
end_date = fields.Datetime(
compute="_get_fake_date", search="_dummy_search"
compute="_compute_fake_date", search="_search_dummy"
)
def _get_utc_date(self, day, hour, minute):
@ -146,7 +146,7 @@ class TaskTemplate(models.Model):
return day_utc_time.replace(tzinfo=None)
@api.depends("start_time", "end_time")
def _get_fake_date(self):
def _compute_fake_date(self):
today = self._context.get("visualize_date", get_first_day_of_week())
for rec in self:
# Find the day of this task template 'rec'.
@ -158,16 +158,16 @@ class TaskTemplate(models.Model):
rec.start_date = self._get_utc_date(day, h_begin, m_begin)
rec.end_date = self._get_utc_date(day, h_end, m_end)
def _dummy_search(self, operator, value):
def _search_dummy(self, operator, value):
return []
@api.depends("worker_ids", "worker_nb")
def _get_remaining(self):
def _compute_remaining(self):
for rec in self:
rec.remaining_worker = rec.worker_nb - len(rec.worker_ids)
@api.depends("worker_ids")
def _get_worker_name(self):
def _compute_worker_name(self):
for rec in self:
rec.worker_name = ",".join(rec.worker_ids.mapped("display_name"))

13
purchase_order_generator/models/purchase_order_generator.py

@ -34,7 +34,7 @@ class PurchaseOrderGenerator(models.Model):
string="Order Lines",
)
total_amount = fields.Float(
string="Total Amount (w/o VAT)", compute="compute_pog_total"
string="Total Amount (w/o VAT)", compute="_compute_pog_total"
)
generated_purchase_order_ids = fields.One2many(
comodel_name="purchase.order",
@ -48,7 +48,7 @@ class PurchaseOrderGenerator(models.Model):
@api.multi
@api.depends("pog_line_ids", "pog_line_ids.purchase_quantity")
def compute_pog_total(self):
def _compute_pog_total(self):
for cpo in self:
total_amount = sum(cpol.subtotal for cpol in cpo.pog_line_ids)
cpo.total_amount = total_amount
@ -60,7 +60,9 @@ class PurchaseOrderGenerator(models.Model):
suppliers = products.mapped("main_supplier_id")
if not suppliers:
raise ValidationError(_("No supplier is set for selected articles."))
raise ValidationError(
_("No supplier is set for selected articles.")
)
elif len(suppliers) == 1:
return suppliers
else:
@ -108,7 +110,10 @@ class PurchaseOrderGenerator(models.Model):
if sum(self.pog_line_ids.mapped("purchase_quantity")) == 0:
raise ValidationError(
_("You need at least a product to generate " "a Purchase Order")
_(
"You need at least a product to generate "
"a Purchase Order"
)
)
purchase_order = self.env["purchase.order"].create(

Loading…
Cancel
Save