Browse Source

[FIX] fix demo data and fix api.one to api.multi

pull/142/head
robin.keunen 4 years ago
parent
commit
6a9d67147c
  1. 6
      beesdoo_base/demo/cooperators.xml
  2. 70
      beesdoo_base/models/partner.py
  3. 116
      beesdoo_product/models/beesdoo_product.py

6
beesdoo_base/demo/cooperators.xml

@ -9,7 +9,6 @@
<field name="firstname">Fernand</field>
<field name="lastname">Peso</field>
<field name="customer" eval="True"/>
<field name="member" eval="True"/>
<field name="eater">worker_eater</field>
<field name="is_company" eval="False"/>
<field name="email">fernand_peso@demo.net</field>
@ -22,7 +21,6 @@
<record id="res_partner_cooperator_2_demo" model="res.partner">
<field name="name">Dupont Dupont</field>
<field name="customer" eval="True"/>
<field name="member" eval="True"/>
<field name="eater">worker_eater</field>
<field name="is_company" eval="False"/>
<field name="email">d_dupont@demo.net</field>
@ -35,7 +33,6 @@
<record id="res_partner_cooperator_3_demo" model="res.partner">
<field name="name">Ronan Le Gall</field>
<field name="customer" eval="True"/>
<field name="member" eval="True"/>
<field name="eater">worker_eater</field>
<field name="is_company" eval="False"/>
<field name="email">ronan_gall@demo.net</field>
@ -48,7 +45,6 @@
<record id="res_partner_cooperator_4_demo" model="res.partner">
<field name="name">Elouan Bees</field>
<field name="customer" eval="True"/>
<field name="member" eval="True"/>
<field name="eater">worker_eater</field>
<field name="is_company" eval="False"/>
<field name="email">elouan_bees@demo.net</field>
@ -61,7 +57,6 @@
<record id="res_partner_cooperator_5_demo" model="res.partner">
<field name="name">Anne de Marchalo</field>
<field name="customer" eval="True"/>
<field name="member" eval="True"/>
<field name="eater">worker_eater</field>
<field name="is_company" eval="False"/>
<field name="email">anne_marchalo@demo.net</field>
@ -74,7 +69,6 @@
<record id="res_partner_cooperator_6_demo" model="res.partner">
<field name="name">Jean Beaumont</field>
<field name="customer" eval="True"/>
<field name="member" eval="True"/>
<field name="eater">worker_eater</field>
<field name="is_company" eval="False"/>
<field name="email">jean_beaumont@demo.net</field>

70
beesdoo_base/models/partner.py

@ -1,3 +1,6 @@
# Copyright 2020 Coop IT Easy SCRL fs
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
@ -24,10 +27,23 @@ class Partner(models.Model):
compute="_compute_bar_code", string="Parent Barcode", store=True
)
member_card_ids = fields.One2many("member.card", "partner_id")
country_id = fields.Many2one(
required=True, default=lambda self: self.env.ref("base.be")
)
member_card_to_be_printed = fields.Boolean("Print BEES card?")
last_printed = fields.Datetime("Last printed on")
cooperator_type = fields.Selection(
[
("share_a", "Share A"),
("share_b", "Share B"),
("share_c", "Share C"),
],
store=True,
compute=None,
)
@api.multi
@api.depends(
"parent_eater_id",
"parent_eater_id.barcode",
@ -35,28 +51,61 @@ class Partner(models.Model):
"member_card_ids",
)
def _compute_bar_code(self):
for rec in self:
if rec.eater == "eater":
rec.parent_barcode = rec.parent_eater_id.barcode
elif rec.member_card_ids:
for c in rec.member_card_ids:
for partner in self:
if partner.eater == "eater":
partner.parent_barcode = partner.parent_eater_id.barcode
elif partner.member_card_ids:
for c in partner.member_card_ids:
if c.valid:
rec.barcode = c.barcode
partner.barcode = c.barcode
@api.multi
@api.constrains("child_eater_ids", "parent_eater_id")
def _check_number_of_eaters(self):
"""The owner of an A share can have a maximum of two eaters but
the owner of a B share can have a maximum of three eaters.
"""
for partner in self:
# Get the default_code of the share for the current eater and his parent
share_type_code = partner.cooperator_type
parent_share_type_code = partner.parent_eater_id.cooperator_type
# Raise exception
if (
share_type_code == "share_b"
or parent_share_type_code == "share_b"
):
if (
len(partner.child_eater_ids) > 3
or len(partner.parent_eater_id.child_eater_ids) > 3
):
raise ValidationError(
_(
"You can only set three additional eaters per worker"
)
)
else:
if (
len(partner.child_eater_ids) > 2
or len(partner.parent_eater_id.child_eater_ids) > 2
):
raise ValidationError(
_("You can only set two additional eaters per worker")
)
@api.multi
def write(self, values):
for rec in self:
for partner in self:
if (
values.get("parent_eater_id")
and rec.parent_eater_id
and rec.parent_eater_id.id != values.get("parent_eater_id")
and partner.parent_eater_id
and partner.parent_eater_id.id != values.get("parent_eater_id")
):
raise ValidationError(
_(
"You try to assign a eater to a worker but this eater "
"is already assign to %s please remove it before "
)
% rec.parent_eater_id.name
% partner.parent_eater_id.name
)
# replace many2many command when writing on child_eater_ids to just
# remove the link
@ -66,6 +115,7 @@ class Partner(models.Model):
command[0] = 3
return super(Partner, self).write(values)
@api.multi
def _deactivate_active_cards(self):
self.ensure_one()
for card in self.member_card_ids.filtered("valid"):

116
beesdoo_product/models/beesdoo_product.py

@ -1,3 +1,6 @@
# Copyright 2020 Coop IT Easy SCRL fs
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import logging
import uuid
@ -150,11 +153,13 @@ class BeesdooProduct(models.Model):
@api.multi
@api.depends("seller_ids", "seller_ids.date_start")
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
sellers_ids = self._get_main_supplier_info()
self.main_seller_id = sellers_ids and sellers_ids[0].name or False
for product in self:
# Calcule le vendeur associé qui a la date de début la plus récente
# et plus petite qu’aujourd’hui
sellers_ids = product._get_main_supplier_info()
product.main_seller_id = (
sellers_ids and sellers_ids[0].name or False
)
@api.multi
@api.depends(
@ -166,57 +171,65 @@ class BeesdooProduct(models.Model):
"weight",
)
def _compute_total(self):
self.ensure_one()
consignes_group = self.env.ref(
"beesdoo_product.consignes_group_tax", raise_if_not_found=False
)
for product in self:
consignes_group = self.env.ref(
"beesdoo_product.consignes_group_tax", raise_if_not_found=False
)
taxes_included = set(self.taxes_id.mapped("price_include"))
if len(taxes_included) == 0:
self.total_with_vat = self.list_price
return True
taxes_included = set(product.taxes_id.mapped("price_include"))
if len(taxes_included) == 0:
product.total_with_vat = product.list_price
return True
elif len(taxes_included) > 1:
raise ValidationError(
_("Several tax strategies (price_include) defined for %s")
% self.name
)
elif len(taxes_included) > 1:
raise ValidationError(
_("Several tax strategies (price_include) defined for %s")
% product.name
)
elif taxes_included.pop():
self.total_with_vat = self.list_price
self.total_deposit = sum(
elif taxes_included.pop():
product.total_with_vat = product.list_price
product.total_deposit = sum(
[
tax._compute_amount(
product.list_price, product.list_price
)
for tax in product.taxes_id
if tax.tax_group_id == consignes_group
]
)
else:
tax_amount_sum = sum(
[
tax._compute_amount(
product.list_price, product.list_price
)
for tax in product.taxes_id
if tax.tax_group_id != consignes_group
]
)
product.total_with_vat = product.list_price + tax_amount_sum
product.total_deposit = sum(
[
tax._compute_amount(self.list_price, self.list_price)
for tax in self.taxes_id
tax._compute_amount(product.list_price, product.list_price)
for tax in product.taxes_id
if tax.tax_group_id == consignes_group
]
)
else:
tax_amount_sum = sum(
[
tax._compute_amount(self.list_price, self.list_price)
for tax in self.taxes_id
if tax.tax_group_id != consignes_group
]
)
self.total_with_vat = self.list_price + tax_amount_sum
self.total_deposit = sum(
[
tax._compute_amount(self.list_price, self.list_price)
for tax in self.taxes_id
if tax.tax_group_id == consignes_group
]
)
if self.display_weight > 0:
self.total_with_vat_by_unit = self.total_with_vat / self.weight
if product.display_weight > 0:
product.total_with_vat_by_unit = (
product.total_with_vat / product.weight
)
@api.multi
@api.depends("weight", "display_unit")
def _compute_display_weight(self):
self.ensure_one()
self.display_weight = self.weight * self.display_unit.factor
for product in self:
product.display_weight = (
product.weight * product.display_unit.factor
)
@api.multi
@api.constrains("display_unit", "default_reference_unit")
@ -236,12 +249,15 @@ class BeesdooProduct(models.Model):
@api.multi
@api.depends("seller_ids")
def _compute_cost(self):
self.ensure_one()
suppliers = self._get_main_supplier_info()
if len(suppliers) > 0:
self.suggested_price = (
suppliers[0].price * self.uom_po_id.factor
) * (1 + suppliers[0].product_tmpl_id.categ_id.profit_margin / 100)
for product in self:
suppliers = product._get_main_supplier_info()
if len(suppliers) > 0:
product.suggested_price = (
suppliers[0].price * product.uom_po_id.factor
) * (
1
+ suppliers[0].product_tmpl_id.categ_id.profit_margin / 100
)
class BeesdooScaleCategory(models.Model):

Loading…
Cancel
Save