Commit 0eded557 authored by Patrick's avatar Patrick

WIP

parent 62ad9f2c
......@@ -251,6 +251,7 @@ class CustomerSendAdmin(admin.ModelAdmin):
.quantize(FOUR_DECIMALS)
else:
purchase.quantity_invoiced = DECIMAL_ZERO
purchase.save()
rule_of_3 = form.cleaned_data['rule_of_3']
if rule_of_3:
if customer_producer_invoice.producer.price_list_multiplier >= DECIMAL_ONE:
......
......@@ -18,7 +18,7 @@ from repanier.admin.fkey_choice_cache_mixin import ForeignKeyCacheMixin
from repanier.const import *
from repanier.fields.RepanierMoneyField import FormMoneyField, RepanierMoney
from repanier.models import Customer, Permanence, Product, LUT_DepartmentForCustomer, Purchase, OfferItem
from repanier.tools import recalculate_prices, recalculate_order_amount
from repanier.tools import recalculate_order_amount
class OfferItemPurchaseSendInlineFormSet(BaseInlineFormSet):
......@@ -172,9 +172,6 @@ class OfferItemSendDataForm(forms.ModelForm):
offer_item.producer_unit_price = producer_unit_price
offer_item.customer_unit_price = customer_unit_price
offer_item.unit_deposit = unit_deposit
recalculate_prices(offer_item, offer_item.producer_price_are_wo_vat,
offer_item.is_resale_price_fixed,
offer_item.price_list_multiplier)
# The previous save is called with "commit=False" or we need to update the producer
# to recalculate the offer item prices. So a call to self.instance.save() is required
offer_item.save()
......
......@@ -96,10 +96,6 @@ class RepanierSettings(AppConfig):
# customer_charged__isnull=True).select_related("customer_invoice").order_by('?'):
# purchase.customer_charged = purchase.customer_invoice.customer_charged
# purchase.save(update_fields=["customer_charged",])
CustomerInvoice.objects.filter(
customer__is_group=True,
customer_id=F('customer_charged_id')
).update(is_group=True)
Staff.objects.rebuild()
# Create groups with correct rights
order_group = Group.objects.filter(name=ORDER_GROUP).only('id').order_by('?').first()
......
......@@ -18,7 +18,7 @@ class Command(BaseCommand):
def handle(self, *args, **options):
recalculate_order_amount(
permanence_id=32,
permanence_id=229,
re_init=True
)
......
......@@ -200,7 +200,8 @@ class CustomerInvoice(models.Model):
transport=delivery_point.transport,
min_transport=delivery_point.min_transport,
is_order_confirm_send=True,
is_group=True
is_group=True,
delivery=delivery
)
@transaction.atomic
......@@ -429,7 +430,7 @@ class CustomerInvoice(models.Model):
class ProducerInvoice(models.Model):
producer = models.ForeignKey(
'Producer', verbose_name=_("producer"),
related_name='producer_invoice',
# related_name='producer_invoice',
on_delete=models.PROTECT)
permanence = models.ForeignKey(
'Permanence', verbose_name=permanence_verbose_name(),
......
# -*- coding: utf-8
from __future__ import unicode_literals
from decimal import ROUND_HALF_UP, getcontext
from parler.models import TranslatableModel
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from repanier.const import BOX_UNICODE, DECIMAL_ZERO, PRODUCT_ORDER_UNIT_PC_KG, PRODUCT_ORDER_UNIT_KG, EMPTY_STRING, \
DECIMAL_ONE, PRODUCT_ORDER_UNIT_PC_PRICE_KG, PRODUCT_ORDER_UNIT_PC_PRICE_LT, PRODUCT_ORDER_UNIT_PC_PRICE_PC, \
TWO_DECIMALS, PRODUCT_ORDER_UNIT_LT, DICT_VAT, DICT_VAT_RATE, FOUR_DECIMALS, PRODUCT_ORDER_UNIT_DEPOSIT
from repanier.fields.RepanierMoneyField import RepanierMoney
from repanier.tools import get_display
@python_2_unicode_compatible
class Item(TranslatableModel):
@property
def producer_unit_price_wo_tax(self):
if self.producer_price_are_wo_vat:
return self.producer_unit_price
else:
return self.producer_unit_price - self.producer_vat
@property
def email_offer_price_with_vat(self):
offer_price = self.get_reference_price()
if offer_price == EMPTY_STRING:
offer_price = self.get_unit_price()
return offer_price
def recalculate_prices(self, producer_price_are_wo_vat, is_resale_price_fixed, price_list_multiplier):
getcontext().rounding = ROUND_HALF_UP
vat = DICT_VAT[self.vat_level]
vat_rate = vat[DICT_VAT_RATE]
if producer_price_are_wo_vat:
self.producer_vat.amount = (self.producer_unit_price.amount * vat_rate).quantize(FOUR_DECIMALS)
if not is_resale_price_fixed:
if self.order_unit < PRODUCT_ORDER_UNIT_DEPOSIT:
self.customer_unit_price.amount = (
self.producer_unit_price.amount * price_list_multiplier).quantize(
TWO_DECIMALS)
else:
self.customer_unit_price = self.producer_unit_price
self.customer_vat.amount = (self.customer_unit_price.amount * vat_rate).quantize(FOUR_DECIMALS)
if not is_resale_price_fixed:
self.customer_unit_price += self.customer_vat
else:
self.producer_vat.amount = self.producer_unit_price.amount - (
self.producer_unit_price.amount / (DECIMAL_ONE + vat_rate)).quantize(
FOUR_DECIMALS)
if not is_resale_price_fixed:
if self.order_unit < PRODUCT_ORDER_UNIT_DEPOSIT:
self.customer_unit_price.amount = (
self.producer_unit_price.amount * price_list_multiplier).quantize(
TWO_DECIMALS)
else:
self.customer_unit_price = self.producer_unit_price
self.customer_vat.amount = self.customer_unit_price.amount - (
self.customer_unit_price.amount / (DECIMAL_ONE + vat_rate)).quantize(
FOUR_DECIMALS)
def get_unit_price(self, customer_price=True):
if customer_price:
unit_price = self.customer_unit_price
else:
unit_price = self.producer_unit_price
if self.order_unit in [PRODUCT_ORDER_UNIT_KG, PRODUCT_ORDER_UNIT_PC_KG]:
return "%s %s" % (unit_price, _("/ kg"))
elif self.order_unit == PRODUCT_ORDER_UNIT_LT:
return "%s %s" % (unit_price, _("/ l"))
elif self.order_unit not in [PRODUCT_ORDER_UNIT_PC_PRICE_KG, PRODUCT_ORDER_UNIT_PC_PRICE_LT,
PRODUCT_ORDER_UNIT_PC_PRICE_PC]:
return "%s %s" % (unit_price, _("/ piece"))
else:
return "%s" % (unit_price,)
def get_reference_price(self, customer_price=True):
if self.order_average_weight > DECIMAL_ZERO and self.order_average_weight != DECIMAL_ONE:
if self.order_unit in [PRODUCT_ORDER_UNIT_PC_PRICE_KG, PRODUCT_ORDER_UNIT_PC_PRICE_LT,
PRODUCT_ORDER_UNIT_PC_PRICE_PC]:
if customer_price:
reference_price = self.customer_unit_price.amount / self.order_average_weight
else:
reference_price = self.producer_unit_price.amount / self.order_average_weight
reference_price = RepanierMoney(reference_price.quantize(TWO_DECIMALS), 2)
if self.order_unit == PRODUCT_ORDER_UNIT_PC_PRICE_KG:
reference_unit = _("/ kg")
elif self.order_unit == PRODUCT_ORDER_UNIT_PC_PRICE_LT:
reference_unit = _("/ l")
else:
reference_unit = _("/ pc")
return "%s %s" % (reference_price, reference_unit)
else:
return EMPTY_STRING
else:
return EMPTY_STRING
def get_qty_display(self, is_quantity_invoiced=False, box_unicode=BOX_UNICODE):
if self.is_box:
# To avoid unicode error in email_offer.send_open_order
qty_display = box_unicode
else:
if is_quantity_invoiced and self.order_unit == PRODUCT_ORDER_UNIT_PC_KG:
qty_display = get_display(
qty=1,
order_average_weight=self.order_average_weight,
order_unit=PRODUCT_ORDER_UNIT_KG,
for_customer=False,
without_price_display=True
)
else:
qty_display = get_display(
qty=1,
order_average_weight=self.order_average_weight,
order_unit=self.order_unit,
for_customer=False,
without_price_display=True
)
return qty_display
def get_qty_and_price_display(self, is_quantity_invoiced=False, customer_price=True, box_unicode=BOX_UNICODE):
qty_display = self.get_qty_display(is_quantity_invoiced, box_unicode)
unit_price = self.get_unit_price(customer_price=customer_price)
if len(qty_display) > 0:
if self.unit_deposit.amount > DECIMAL_ZERO:
return '%s; %s + ♻ %s' % (
qty_display, unit_price, self.unit_deposit)
else:
return '%s; %s' % (qty_display, unit_price)
else:
if self.unit_deposit.amount > DECIMAL_ZERO:
return '%s + ♻ %s' % (
unit_price, self.unit_deposit)
else:
return '%s' % unit_price
def get_order_name(self, is_quantity_invoiced=False, box_unicode=BOX_UNICODE):
qty_display = self.get_qty_display(is_quantity_invoiced, box_unicode)
if qty_display:
return '%s %s' % (self.long_name, qty_display)
return '%s' % self.long_name
def get_long_name_with_producer_price(self):
return self.get_long_name(customer_price=False)
get_long_name_with_producer_price.short_description = (_("long_name"))
get_long_name_with_producer_price.allow_tags = False
get_long_name_with_producer_price.admin_order_field = 'translations__long_name'
def get_long_name(self, is_quantity_invoiced=False, customer_price=True, box_unicode=BOX_UNICODE):
qty_and_price_display = self.get_qty_and_price_display(is_quantity_invoiced, customer_price, box_unicode)
if qty_and_price_display:
result = '%s %s' % (self.long_name, qty_and_price_display)
else:
result = '%s' % self.long_name
if self.is_box_content:
return "%s %s" % (result, BOX_UNICODE)
else:
return result
get_long_name.short_description = (_("long_name"))
get_long_name.allow_tags = False
get_long_name.admin_order_field = 'translations__long_name'
def display(self):
if self.id is not None:
return '%s, %s' % (self.producer.short_profile_name, self.get_long_name())
else:
# Nedeed for django import export since django_import_export-0.4.5
return 'N/A'
def __str__(self):
return self.display()
class Meta:
abstract = True
\ No newline at end of file
......@@ -11,19 +11,19 @@ from django.utils.encoding import python_2_unicode_compatible
from django.utils.formats import number_format
from django.utils.translation import ugettext_lazy as _
from djangocms_text_ckeditor.fields import HTMLField
from parler.models import TranslatableModel, TranslatedFields
from parler.models import TranslatedFields
import invoice
from repanier.models.item import Item
from repanier.apps import REPANIER_SETTINGS_PERMANENCE_NAME
from repanier.const import *
from repanier.fields.RepanierMoneyField import ModelMoneyField, RepanierMoney
from repanier.picture.const import SIZE_M
from repanier.picture.fields import AjaxPictureField
from repanier.tools import get_display
@python_2_unicode_compatible
class OfferItem(TranslatableModel):
class OfferItem(Item):
translations = TranslatedFields(
long_name=models.CharField(_("long_name"), max_length=100,
default=EMPTY_STRING, blank=True, null=True),
......@@ -171,18 +171,6 @@ class OfferItem(TranslatableModel):
help_text=_('1,5 Kg [i.e. 1500 gr], 1 piece, 3 Kg)'),
default=DECIMAL_ZERO, max_digits=6, decimal_places=3)
def get_producer(self):
return self.producer.short_profile_name
get_producer.short_description = (_("producers"))
get_producer.allow_tags = False
def get_product(self):
return self.product.long_name
get_product.short_description = (_("products"))
get_product.allow_tags = False
def get_vat_level(self):
return self.get_vat_level_display()
......@@ -266,125 +254,13 @@ class OfferItem(TranslatableModel):
get_html_producer_price_purchased.allow_tags = True
get_html_producer_price_purchased.admin_order_field = 'total_purchase_with_tax'
@property
def producer_unit_price_wo_tax(self):
if self.producer_price_are_wo_vat:
return self.producer_unit_price
else:
return self.producer_unit_price - self.producer_vat
def get_unit_price(self, customer_price=True):
if customer_price:
unit_price = self.customer_unit_price
else:
unit_price = self.producer_unit_price
if self.order_unit in [PRODUCT_ORDER_UNIT_KG, PRODUCT_ORDER_UNIT_PC_KG]:
return "%s %s" % (unit_price, _("/ kg"))
elif self.order_unit == PRODUCT_ORDER_UNIT_LT:
return "%s %s" % (unit_price, _("/ l"))
elif self.order_unit not in [PRODUCT_ORDER_UNIT_PC_PRICE_KG, PRODUCT_ORDER_UNIT_PC_PRICE_LT,
PRODUCT_ORDER_UNIT_PC_PRICE_PC]:
return "%s %s" % (unit_price, _("/ piece"))
else:
return "%s" % (unit_price,)
def get_reference_price(self, customer_price=True):
if self.order_average_weight > DECIMAL_ZERO and self.order_average_weight != DECIMAL_ONE:
if self.order_unit in [PRODUCT_ORDER_UNIT_PC_PRICE_KG, PRODUCT_ORDER_UNIT_PC_PRICE_LT,
PRODUCT_ORDER_UNIT_PC_PRICE_PC]:
if customer_price:
reference_price = self.customer_unit_price.amount / self.order_average_weight
else:
reference_price = self.producer_unit_price.amount / self.order_average_weight
reference_price = RepanierMoney(reference_price.quantize(TWO_DECIMALS), 2)
if self.order_unit == PRODUCT_ORDER_UNIT_PC_PRICE_KG:
reference_unit = _("/ kg")
elif self.order_unit == PRODUCT_ORDER_UNIT_PC_PRICE_LT:
reference_unit = _("/ l")
else:
reference_unit = _("/ pc")
return "%s %s" % (reference_price, reference_unit)
else:
return EMPTY_STRING
else:
return EMPTY_STRING
@property
def email_offer_price_with_vat(self):
offer_price = self.get_reference_price()
if offer_price == EMPTY_STRING:
offer_price = self.get_unit_price()
return offer_price
def get_like(self, user):
return '<span class="glyphicon glyphicon-heart%s" onclick="like_ajax(%d);return false;"></span>' % (
EMPTY_STRING if self.product.likes.filter(id=user.id).only("id").exists() else "-empty", self.id)
def get_qty_display(self, is_quantity_invoiced=False, box_unicode=BOX_UNICODE):
if self.is_box:
# To avoid unicode error in email_offer.send_open_order
qty_display = box_unicode
else:
if is_quantity_invoiced and self.order_unit == PRODUCT_ORDER_UNIT_PC_KG:
qty_display = get_display(
qty=1,
order_average_weight=self.order_average_weight,
order_unit=PRODUCT_ORDER_UNIT_KG,
for_customer=False,
without_price_display=True
)
else:
qty_display = get_display(
qty=1,
order_average_weight=self.order_average_weight,
order_unit=self.order_unit,
for_customer=False,
without_price_display=True
)
return qty_display
def get_qty_and_price_display(self, is_quantity_invoiced=False, customer_price=True, box_unicode=BOX_UNICODE):
qty_display = self.get_qty_display(is_quantity_invoiced, box_unicode)
unit_price = self.get_unit_price(customer_price=customer_price)
if len(qty_display) > 0:
if self.unit_deposit.amount > DECIMAL_ZERO:
return '%s; %s + ♻ %s' % (
qty_display, unit_price, self.unit_deposit)
else:
return '%s; %s' % (qty_display, unit_price)
else:
if self.unit_deposit.amount > DECIMAL_ZERO:
return '%s + ♻ %s' % (
unit_price, self.unit_deposit)
else:
return '%s' % unit_price
def get_order_name(self, is_quantity_invoiced=False, box_unicode=BOX_UNICODE):
qty_display = self.get_qty_display(is_quantity_invoiced, box_unicode)
if qty_display:
return '%s %s' % (self.long_name, qty_display)
return '%s' % self.long_name
def get_long_name_with_producer_price(self):
return self.get_long_name(customer_price=False)
get_long_name_with_producer_price.short_description = (_("long_name"))
get_long_name_with_producer_price.allow_tags = False
get_long_name_with_producer_price.admin_order_field = 'translations__long_name'
def get_long_name(self, is_quantity_invoiced=False, customer_price=True, box_unicode=BOX_UNICODE):
qty_and_price_display = self.get_qty_and_price_display(is_quantity_invoiced, customer_price, box_unicode)
if qty_and_price_display:
return '%s %s' % (self.long_name, qty_and_price_display)
return '%s' % self.long_name
get_long_name.short_description = (_("long_name"))
get_long_name.allow_tags = False
get_long_name.admin_order_field = 'translations__long_name'
def __str__(self):
return '%s, %s' % (self.producer.short_profile_name, self.get_long_name())
return super(OfferItem, self).display()
# return '%s, %s' % (self.producer.short_profile_name, self.get_long_name())
class Meta:
verbose_name = _("offer's item")
......@@ -411,6 +287,8 @@ def offer_item_post_init(sender, **kwargs):
@receiver(pre_save, sender=OfferItem)
def offer_item_pre_save(sender, **kwargs):
offer_item = kwargs["instance"]
offer_item.recalculate_prices(offer_item.producer_price_are_wo_vat, offer_item.is_resale_price_fixed,
offer_item.price_list_multiplier)
if offer_item.manage_replenishment:
if (offer_item.previous_add_2_stock != offer_item.add_2_stock or
offer_item.previous_producer_unit_price != offer_item.producer_unit_price.amount or
......
......@@ -283,19 +283,29 @@ class Permanence(TranslatableModel):
'admin:repanier_purchase_changelist',
)
link = []
delivery_save = None
for ci in invoice.CustomerInvoice.objects.filter(permanence_id=self.id).select_related(
"customer").order_by('customer'):
"customer").order_by('delivery', 'customer'):
if delivery_save != ci.delivery:
delivery_save = ci.delivery
if ci.delivery is not None:
link.append("<br/><b>%s</b>" % ci.delivery.get_delivery_display())
else:
link.append("<br/><br/>--")
total_price_with_tax = ci.get_total_price_with_tax(customer_charged=True)
if ci.is_order_confirm_send:
label = '%s%s (%s) %s%s' % (
"<b><i>" if ci.is_group else EMPTY_STRING,
ci.customer.short_basket_name, "-" if ci.is_group else ci.get_total_price_with_tax(customer_charged=True),
ci.customer.short_basket_name,
"-" if ci.is_group or total_price_with_tax == DECIMAL_ZERO else total_price_with_tax,
ci.get_is_order_confirm_send_display(),
"</i></b>" if ci.is_group else EMPTY_STRING,
)
else:
label = '%s%s (%s) %s%s' % (
"<b><i>" if ci.is_group else EMPTY_STRING,
ci.customer.short_basket_name, "-" if ci.is_group else ci.total_price_with_tax,
ci.customer.short_basket_name,
"-" if ci.is_group or total_price_with_tax == DECIMAL_ZERO else total_price_with_tax,
ci.get_is_order_confirm_send_display(),
"</i></b>" if ci.is_group else EMPTY_STRING,
)
......@@ -306,12 +316,20 @@ class Permanence(TranslatableModel):
customers = ", ".join(link)
elif self.status in [PERMANENCE_INVOICED, PERMANENCE_ARCHIVED]:
link = []
delivery_save = None
for ci in invoice.CustomerInvoice.objects.filter(permanence_id=self.id).select_related(
"customer").order_by('customer'):
"customer").order_by('delivery', 'customer'):
if delivery_save != ci.delivery:
delivery_save = ci.delivery
if ci.delivery is not None:
link.append("<br/><b>%s</b>" % ci.delivery.get_delivery_display())
else:
link.append("<br/><br/>--")
total_price_with_tax = ci.get_total_price_with_tax(customer_charged=True)
label = "%s%s (%s) %s%s" % (
"<b><i>" if ci.is_group else EMPTY_STRING,
ci.customer.short_basket_name,
ci.get_total_price_with_tax(customer_charged=True),
"-" if total_price_with_tax == DECIMAL_ZERO else total_price_with_tax,
ci.get_is_order_confirm_send_display(),
"</i></b>" if ci.is_group else EMPTY_STRING,
)
......@@ -692,22 +710,6 @@ class Permanence(TranslatableModel):
get_permanence_admin_display.short_description = lambda: "%s" % repanier.apps.REPANIER_SETTINGS_PERMANENCES_NAME
get_permanence_admin_display.allow_tags = True
# def get_permanence_order_display(self):
# if self.with_delivery_point:
# if self.status == PERMANENCE_OPENED:
# deliveries_count = 0
# else:
# deliveries_qs = deliveryboard.DeliveryBoard.objects.filter(
# permanence_id=self.id,
# status=PERMANENCE_OPENED
# ).order_by('?')
# deliveries_count = deliveries_qs.count()
# else:
# deliveries_count = 0
# if deliveries_count == 0:
# return "%s - %s" % (self.get_permanence_display(), self.get_status_display())
# return self.get_permanence_display()
def get_permanence_customer_display(self, with_status=True):
if with_status:
if self.with_delivery_point:
......
......@@ -14,18 +14,17 @@ from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from djangocms_text_ckeditor.fields import HTMLField
from parler.fields import TranslatedField
from parler.models import TranslatableModel
from parler.models import TranslatedFieldsModel
from repanier.models.item import Item
from repanier.const import *
from repanier.fields.RepanierMoneyField import ModelMoneyField, RepanierMoney
from repanier.fields.RepanierMoneyField import ModelMoneyField
from repanier.picture.const import SIZE_M
from repanier.picture.fields import AjaxPictureField
from repanier.tools import get_display, recalculate_prices
@python_2_unicode_compatible
class Product(TranslatableModel):
class Product(Item):
producer = models.ForeignKey(
'Producer', verbose_name=_("producer"), on_delete=models.PROTECT)
long_name = TranslatedField()
......@@ -127,13 +126,12 @@ class Product(TranslatableModel):
default=False)
is_box = models.BooleanField(_("is_box"), default=False)
is_box_content = models.BooleanField(_("is_box_content"), default=False)
# is_mandatory = models.BooleanField(_("is_mandatory"), default=False)
# is_membership_fee = models.BooleanField(_("is_membership_fee"), default=False)
is_active = models.BooleanField(_("is_active"), default=True)
is_updated_on = models.DateTimeField(
_("is_updated_on"), auto_now=True, blank=True)
# external_id_producer = models.BigIntegerField(null=True, blank=True, default=None)
# external_id_product = models.BigIntegerField(null=True, blank=True, default=None)
@property
def total_likes(self):
......@@ -167,7 +165,8 @@ class Product(TranslatableModel):
LINK=switch_is_into_offer,
PRODUCT_ID=self.id
)
link = '<a id="is_into_offer_%d" href="#" onclick="%s" class="btn">%s</a>' % (
# return false; http://stackoverflow.com/questions/1601933/how-do-i-stop-a-web-page-from-scrolling-to-the-top-when-a-link-is-clicked-that-t
link = '<a id="is_into_offer_%d" href="#" onclick="%s;return false;" class="btn">%s</a>' % (
self.id,
javascript,
_boolean_icon(self.is_into_offer)
......@@ -185,112 +184,13 @@ class Product(TranslatableModel):
get_customer_alert_order_quantity.short_description = (_("customer_alert_order_quantity"))
get_customer_alert_order_quantity.allow_tags = False
def get_unit_price(self, customer_price=True):
if customer_price:
unit_price = self.customer_unit_price
else:
unit_price = self.producer_unit_price
if self.order_unit in [PRODUCT_ORDER_UNIT_KG, PRODUCT_ORDER_UNIT_PC_KG]:
return "%s %s" % (unit_price, _("/ kg"))
elif self.order_unit == PRODUCT_ORDER_UNIT_LT:
return "%s %s" % (unit_price, _("/ l"))
elif self.order_unit not in [PRODUCT_ORDER_UNIT_PC_PRICE_KG, PRODUCT_ORDER_UNIT_PC_PRICE_LT,
PRODUCT_ORDER_UNIT_PC_PRICE_PC]:
return "%s %s" % (unit_price, _("/ piece"))
else:
return "%s" % (unit_price,)
@property
def unit_price_with_vat(self, customer_price=True):
return self.get_unit_price(customer_price=customer_price)
def get_reference_price(self, customer_price=True):
if self.order_average_weight > DECIMAL_ZERO and self.order_average_weight != DECIMAL_ONE:
if self.order_unit in [PRODUCT_ORDER_UNIT_PC_PRICE_KG, PRODUCT_ORDER_UNIT_PC_PRICE_LT,
PRODUCT_ORDER_UNIT_PC_PRICE_PC]:
if customer_price:
reference_price = self.customer_unit_price.amount / self.order_average_weight
else:
reference_price = self.producer_unit_price.amount / self.order_average_weight
reference_price = RepanierMoney(reference_price.quantize(TWO_DECIMALS), 2)
if self.order_unit == PRODUCT_ORDER_UNIT_PC_PRICE_KG:
reference_unit = _("/ kg")
elif self.order_unit == PRODUCT_ORDER_UNIT_PC_PRICE_LT:
reference_unit = _("/ l")
else:
reference_unit = _("/ pc")
return "%s %s" % (reference_price, reference_unit)
else:
return EMPTY_STRING
else:
return EMPTY_STRING
@property
def reference_price_with_vat(self):
return self.get_reference_price()
@property
def email_offer_price_with_vat(self):
offer_price = self.get_reference_price()
if offer_price == EMPTY_STRING:
offer_price = self.get_unit_price()
return offer_price
def get_qty_display(self, is_quantity_invoiced=False, box_unicode=BOX_UNICODE):
if self.is_box:
# To avoid unicode error in email_offer.send_open_order
qty_display = box_unicode
else:
if is_quantity_invoiced and self.order_unit == PRODUCT_ORDER_UNIT_PC_KG:
qty_display = get_display(
qty=1,
order_average_weight=self.order_average_weight,
order_unit=PRODUCT_ORDER_UNIT_KG,
for_customer=False,
without_price_display=True
)
else:
qty_display = get_display(
qty=1,
order_average_weight=self.order_average_weight,
order_unit=self.order_unit,
for_customer=False,
without_price_display=True
)
return qty_display
def get_qty_and_price_display(self, is_quantity_invoiced=False, customer_price=True, box_unicode=BOX_UNICODE):
qty_display = self.get_qty_display(is_quantity_invoiced, box_unicode)
unit_price = self.get_unit_price(customer_price=customer_price)
if len(qty_display) > 0:
if self.unit_deposit.amount > DECIMAL_ZERO:
return '%s; %s + ♻ %s' % (
qty_display, unit_price, self.unit_deposit)
else:
return '%s; %s' % (qty_display, unit_price)
else:
if self.unit_deposit.amount > DECIMAL_ZERO:
return '%s + ♻ %s' % (
unit_price, self.unit_deposit)
else:
return '%s' % unit_price
def get_long_name(self, is_quantity_invoiced=False, customer_price=True, box_unicode=BOX_UNICODE):
qty_and_price_display = self.get_qty_and_price_display(is_quantity_invoiced, customer_price, box_unicode)
if qty_and_price_display:
return '%s %s' % (self.long_name, qty_and_price_display)
return "%s" % self.long_name
get_long_name.short_description = (_("long_name"))
get_long_name.allow_tags = True
get_long_name.admin_order_field = 'translations__long_name'
def __str__(self):
if self.id is not None:
return '%s, %s' % (self.producer.short_profile_name, self.get_long_name())
else:
# Nedeed for django import export since django_import_export-0.4.5
return 'N/A'
return super(Product, self).display()
# if self.id is not None:
# return '%s, %s' % (self.producer.short_profile_name, self.get_long_name())
# else:
# # Nedeed for django import export since django_import_export-0.4.5
# return 'N/A'
class Meta:
verbose_name = _("product")
......@@ -321,7 +221,7 @@ def product_pre_save(sender, **kwargs):
# No VAT on those products
product.vat_level = VAT_100
recalculate_prices(product, producer.producer_price_are_wo_vat, producer.is_resale_price_fixed,
product.recalculate_prices(producer.producer_price_are_wo_vat, producer.is_resale_price_fixed,
producer.price_list_multiplier)
if producer.producer_pre_opening or producer.manage_production:
......
......@@ -39,12 +39,8 @@ class Purchase(models.Model):
producer.Producer, verbose_name=_("producer"), on_delete=models.PROTECT)
customer = models.ForeignKey(
'Customer', verbose_name=_("customer"), on_delete=models.PROTECT, db_index=True)
# customer_charged = models.ForeignKey(
# 'Customer', verbose_name=_("customer"), related_name='purchase_paid', blank=True, null=True,
# on_delete=models.PROTECT, db_index=True)
customer_producer_invoice = models.ForeignKey(
'CustomerProducerInvoice', verbose_name=_("customer_producer_invoice"),
# related_name = 'purchase_invoiced',
on_delete=models.PROTECT, db_index=True)
producer_invoice = models.ForeignKey(
'ProducerInvoice', verbose_name=_("producer_invoice"),
......@@ -53,6 +49,7 @@ class Purchase(models.Model):
'CustomerInvoice', verbose_name=_("customer_invoice"),
on_delete=models.PROTECT, db_index=True)
is_box = models.BooleanField(_("is_box"), default=False)
is_box_content = models.BooleanField(_("is_box"), default=False)
quantity_ordered = models.DecimalField(
......@@ -91,12 +88,6 @@ class Purchase(models.Model):
default=DECIMAL_ZERO, max_digits=8, decimal_places=2,
validators=[MinValueValidator(0)])
vat_level = models.CharField(
max_length=3,
choices=LUT_ALL_VAT, # settings.LUT_VAT,