Commit fee7c6a6 authored by Patrick's avatar Patrick

Code clean up, use of abstract model

parent 0eded557
......@@ -492,7 +492,8 @@ class PurchaseAdmin(ExportMixin, admin.ModelAdmin):
permanence_id=purchase.permanence_id).order_by('?').first()
else:
# New : product_or_offer_item_id is a product_id
offer_item = get_or_create_offer_item(purchase.permanence, product_or_offer_item_id, self.producer_id)
product = Product.objects.filter(id=product_or_offer_item_id).order_by('?').first()
offer_item = get_or_create_offer_item(purchase.permanence, product)
# Select one purchase
previous_purchase = Purchase.objects.filter(
customer=purchase.customer,
......
......@@ -26,39 +26,16 @@ def permanence_verbose_name():
from repanier.apps import REPANIER_SETTINGS_PERMANENCE_NAME
return _('order') # lambda: "%s" % REPANIER_SETTINGS_PERMANENCE_NAME
@python_2_unicode_compatible
class CustomerInvoice(models.Model):
customer = models.ForeignKey(
'Customer', verbose_name=_("customer"),
on_delete=models.PROTECT)
customer_charged = models.ForeignKey(
'Customer', verbose_name=_("customer"), related_name='invoices_paid', blank=True, null=True,
on_delete=models.PROTECT, db_index=True)
class Invoice(models.Model):
permanence = models.ForeignKey(
'Permanence', verbose_name=permanence_verbose_name(),
on_delete=models.PROTECT, db_index=True)
delivery = models.ForeignKey(
'DeliveryBoard', verbose_name=_("delivery board"),
null=True, blank=True, default=None,
on_delete=models.PROTECT)
status = models.CharField(
max_length=3,
choices=LUT_PERMANENCE_STATUS,
default=PERMANENCE_PLANNED,
verbose_name=_("invoice_status"))
# IMPORTANT: default = True -> for the order form, to display nothing at the begin of the order
# is_order_confirm_send and total_price_with_tax = 0 --> display nothing
# otherwise display
# - send a mail with the order to me
# - confirm the order (if REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS) and send a mail with the order to me
# - mail send to XYZ
# - order confirmed (if REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS) and mail send to XYZ
is_order_confirm_send = models.BooleanField(_("is_order_confirm_send"), choices=LUT_CONFIRM, default=False)
invoice_sort_order = models.IntegerField(
_("invoice sort order"),
default=None, blank=True, null=True, db_index=True)
date_previous_balance = models.DateField(
_("date_previous_balance"), default=datetime.date.today)
previous_balance = ModelMoneyField(
......@@ -68,27 +45,27 @@ class CustomerInvoice(models.Model):
_("Total amount"),
help_text=_('Total purchase amount vat included'),
default=DECIMAL_ZERO, max_digits=8, decimal_places=2)
total_vat = ModelMoneyField(
_("Total vat"),
help_text=_('Vat part of the total purchased'),
default=DECIMAL_ZERO, max_digits=9, decimal_places=4)
total_deposit = ModelMoneyField(
_("deposit"),
help_text=_('deposit to add to the original unit price'),
default=DECIMAL_ZERO, max_digits=8, decimal_places=2)
delta_price_with_tax = ModelMoneyField(
_("Total amount"),
help_text=_('purchase to add amount vat included'),
default=DECIMAL_ZERO, max_digits=8, decimal_places=2)
delta_vat = ModelMoneyField(
_("Total vat"),
help_text=_('vat to add'),
default=DECIMAL_ZERO, max_digits=9, decimal_places=4)
delta_transport = ModelMoneyField(
_("Delivery point transport"),
help_text=_("transport to add"),
default=DECIMAL_ZERO, max_digits=5, decimal_places=2,
validators=[MinValueValidator(0)])
total_vat = ModelMoneyField(
_("Total vat"),
help_text=_('Vat part of the total purchased'),
default=DECIMAL_ZERO, max_digits=9, decimal_places=4)
delta_vat = ModelMoneyField(
_("Total vat"),
help_text=_('vat to add'),
default=DECIMAL_ZERO, max_digits=9, decimal_places=4)
total_deposit = ModelMoneyField(
_("deposit"),
help_text=_('deposit to add to the original unit price'),
default=DECIMAL_ZERO, max_digits=8, decimal_places=2)
bank_amount_in = ModelMoneyField(
_("bank_amount_in"), help_text=_('payment_on_the_account'),
max_digits=8, decimal_places=2, default=DECIMAL_ZERO)
......@@ -100,6 +77,42 @@ class CustomerInvoice(models.Model):
balance = ModelMoneyField(
_("balance"),
max_digits=8, decimal_places=2, default=DECIMAL_ZERO)
def get_delta_price_with_tax(self):
return self.delta_price_with_tax.amount
def get_abs_delta_price_with_tax(self):
return abs(self.delta_price_with_tax.amount)
def __str__(self):
return _("Invoice")
class Meta:
abstract = True
@python_2_unicode_compatible
class CustomerInvoice(Invoice):
customer = models.ForeignKey(
'Customer', verbose_name=_("customer"),
on_delete=models.PROTECT)
customer_charged = models.ForeignKey(
'Customer', verbose_name=_("customer"), related_name='invoices_paid', blank=True, null=True,
on_delete=models.PROTECT, db_index=True)
delivery = models.ForeignKey(
'DeliveryBoard', verbose_name=_("delivery board"),
null=True, blank=True, default=None,
on_delete=models.PROTECT)
# IMPORTANT: default = True -> for the order form, to display nothing at the begin of the order
# is_order_confirm_send and total_price_with_tax = 0 --> display nothing
# otherwise display
# - send a mail with the order to me
# - confirm the order (if REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS) and send a mail with the order to me
# - mail send to XYZ
# - order confirmed (if REPANIER_SETTINGS_CUSTOMERS_MUST_CONFIRM_ORDERS) and mail send to XYZ
is_order_confirm_send = models.BooleanField(_("is_order_confirm_send"), choices=LUT_CONFIRM, default=False)
invoice_sort_order = models.IntegerField(
_("invoice sort order"),
default=None, blank=True, null=True, db_index=True)
price_list_multiplier = models.DecimalField(
_("Delivery point price list multiplier"),
help_text=_("This multiplier is applied once for groups with entitled customer or at each customer invoice for open groups."),
......@@ -122,12 +135,6 @@ class CustomerInvoice(models.Model):
on_delete=models.PROTECT, db_index=True)
is_group = models.BooleanField(_("is a group"), default=False)
def get_delta_price_with_tax(self):
return self.delta_price_with_tax.amount
def get_abs_delta_price_with_tax(self):
return abs(self.delta_price_with_tax)
def get_abs_delta_vat(self):
return abs(self.delta_vat)
......@@ -427,68 +434,21 @@ class CustomerInvoice(models.Model):
@python_2_unicode_compatible
class ProducerInvoice(models.Model):
class ProducerInvoice(Invoice):
producer = models.ForeignKey(
'Producer', verbose_name=_("producer"),
# related_name='producer_invoice',
on_delete=models.PROTECT)
permanence = models.ForeignKey(
'Permanence', verbose_name=permanence_verbose_name(),
on_delete=models.PROTECT, db_index=True)
status = models.CharField(
max_length=3,
choices=LUT_PERMANENCE_STATUS,
default=PERMANENCE_PLANNED,
verbose_name=_("invoice_status"))
date_previous_balance = models.DateField(
_("date_previous_balance"), default=datetime.date.today)
previous_balance = ModelMoneyField(
_("previous_balance"), max_digits=8, decimal_places=2, default=DECIMAL_ZERO)
# Calculated with Purchase
total_price_with_tax = ModelMoneyField(
_("Total amount"),
help_text=_('Total purchase amount vat included'),
default=DECIMAL_ZERO, max_digits=8, decimal_places=2)
total_vat = ModelMoneyField(
_("Total vat"),
help_text=_('Vat part of the total purchased'),
default=DECIMAL_ZERO, max_digits=9, decimal_places=4)
total_deposit = ModelMoneyField(
_("deposit"),
help_text=_('deposit to add to the original unit price'),
default=DECIMAL_ZERO, max_digits=8, decimal_places=2)
bank_amount_in = ModelMoneyField(
_("bank_amount_in"), help_text=_('payment_on_the_account'),
max_digits=8, decimal_places=2, default=DECIMAL_ZERO)
bank_amount_out = ModelMoneyField(
_("bank_amount_out"), help_text=_('payment_from_the_account'),
max_digits=8, decimal_places=2, default=DECIMAL_ZERO)
date_balance = models.DateField(
_("date_balance"), default=datetime.date.today)
balance = ModelMoneyField(
_("balance"),
max_digits=8, decimal_places=2, default=DECIMAL_ZERO)
delta_price_with_tax = ModelMoneyField(
_("Total amount"),
help_text=_('purchase to add amount vat included'),
default=DECIMAL_ZERO, max_digits=8, decimal_places=2)
delta_stock_with_tax = ModelMoneyField(
_("Total stock"),
help_text=_('stock taken amount vat included'),
default=DECIMAL_ZERO, max_digits=8, decimal_places=2)
delta_vat = ModelMoneyField(
_("Total vat"),
help_text=_('vat to add'),
default=DECIMAL_ZERO, max_digits=9, decimal_places=4)
delta_stock_vat = ModelMoneyField(
_("Total stock vat"),
help_text=_('vat to add'),
default=DECIMAL_ZERO, max_digits=9, decimal_places=4)
delta_transport = ModelMoneyField(
_("Delivery point transport"),
help_text=_("transport to add"),
default=DECIMAL_ZERO, max_digits=5, decimal_places=2,
validators=[MinValueValidator(0)])
delta_deposit = ModelMoneyField(
_("deposit"),
help_text=_('deposit to add'),
......@@ -515,12 +475,6 @@ class ProducerInvoice(models.Model):
def get_negative_balance(self):
return - self.balance
def get_delta_price_with_tax(self):
return self.delta_price_with_tax.amount
def get_abs_delta_price_with_tax(self):
return abs(self.delta_price_with_tax)
def get_total_price_with_tax(self):
return self.total_price_with_tax + self.delta_price_with_tax + self.delta_transport + self.delta_stock_with_tax
......
......@@ -3,19 +3,124 @@ from __future__ import unicode_literals
from decimal import ROUND_HALF_UP, getcontext
from parler.models import TranslatableModel
from django.conf import settings
from django.core.validators import MinValueValidator
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from parler.models import TranslatableModel
from repanier.picture.const import SIZE_M
from repanier.picture.fields import AjaxPictureField
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
TWO_DECIMALS, PRODUCT_ORDER_UNIT_LT, DICT_VAT, DICT_VAT_RATE, FOUR_DECIMALS, PRODUCT_ORDER_UNIT_DEPOSIT, \
LUT_PRODUCT_ORDER_UNIT, PRODUCT_ORDER_UNIT_PC, LUT_PRODUCT_PLACEMENT, PRODUCT_PLACEMENT_BASKET, LUT_ALL_VAT, \
LIMIT_ORDER_QTY_ITEM
from repanier.fields.RepanierMoneyField import RepanierMoney, ModelMoneyField
from repanier.tools import get_display
@python_2_unicode_compatible
class Item(TranslatableModel):
producer = models.ForeignKey(
'Producer',
verbose_name=_("producer"),
on_delete=models.PROTECT)
department_for_customer = models.ForeignKey(
'LUT_DepartmentForCustomer',
verbose_name=_("department_for_customer"),
blank=True, null=True,
on_delete=models.PROTECT)
picture2 = AjaxPictureField(
verbose_name=_("picture"),
null=True, blank=True,
upload_to="product", size=SIZE_M)
reference = models.CharField(
_("reference"), max_length=36,
blank=True, null=True)
order_unit = models.CharField(
max_length=3,
choices=LUT_PRODUCT_ORDER_UNIT,
default=PRODUCT_ORDER_UNIT_PC,
verbose_name=_("order unit"),
)
order_average_weight = models.DecimalField(
_("order_average_weight"),
help_text=_('if useful, average order weight (eg : 0,1 Kg [i.e. 100 gr], 3 Kg)'),
default=DECIMAL_ZERO, max_digits=6, decimal_places=3,
validators=[MinValueValidator(0)])
producer_unit_price = ModelMoneyField(
_("producer unit price"),
default=DECIMAL_ZERO, max_digits=8, decimal_places=2)
customer_unit_price = ModelMoneyField(
_("customer unit price"),
default=DECIMAL_ZERO, max_digits=8, decimal_places=2)
producer_vat = ModelMoneyField(
_("vat"),
default=DECIMAL_ZERO, max_digits=8, decimal_places=4)
customer_vat = ModelMoneyField(
_("vat"),
default=DECIMAL_ZERO, max_digits=8, decimal_places=4)
unit_deposit = ModelMoneyField(
_("deposit"),
help_text=_('deposit to add to the original unit price'),
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,
default=settings.DICT_VAT_DEFAULT,
verbose_name=_("tax"))
wrapped = models.BooleanField(
_('Individually wrapped by the producer'),
default=False)
customer_minimum_order_quantity = models.DecimalField(
_("customer_minimum_order_quantity"),
help_text=_('minimum order qty (eg : 0,1 Kg [i.e. 100 gr], 1 piece, 3 Kg)'),
default=DECIMAL_ONE, max_digits=6, decimal_places=3,
validators=[MinValueValidator(0)])
customer_increment_order_quantity = models.DecimalField(
_("customer_increment_order_quantity"),
help_text=_('increment order qty (eg : 0,05 Kg [i.e. 50max 1 piece, 3 Kg)'),
default=DECIMAL_ONE, max_digits=6, decimal_places=3,
validators=[MinValueValidator(0)])
customer_alert_order_quantity = models.DecimalField(
_("customer_alert_order_quantity"),
help_text=_('maximum order qty before alerting the customer to check (eg : 1,5 Kg, 12 pieces, 9 Kg)'),
default=LIMIT_ORDER_QTY_ITEM, max_digits=6, decimal_places=3,
validators=[MinValueValidator(0)])
producer_order_by_quantity = models.DecimalField(
_("Producer order by quantity"),
help_text=_('1,5 Kg [i.e. 1500 gr], 1 piece, 3 Kg)'),
default=DECIMAL_ZERO, max_digits=6, decimal_places=3,
validators=[MinValueValidator(0)])
placement = models.CharField(
max_length=3,
choices=LUT_PRODUCT_PLACEMENT,
default=PRODUCT_PLACEMENT_BASKET,
verbose_name=_("product_placement"),
help_text=_('used for helping to determine the order of preparation of this product'))
stock = models.DecimalField(
_("Current stock"),
default=DECIMAL_ZERO, max_digits=9, decimal_places=3,
validators=[MinValueValidator(0)])
limit_order_quantity_to_stock = models.BooleanField(
_("limit maximum order qty of the group to stock qty"),
default=False
)
is_box = models.BooleanField(_("is_box"), default=False)
is_box_content = models.BooleanField(_("is_box_content"), default=False)
# is_membership_fee = models.BooleanField(_("is_membership_fee"), default=False)
# may_order = models.BooleanField(_("may_order"), default=True)
is_active = models.BooleanField(_("is_active"), default=True)
@property
def producer_unit_price_wo_tax(self):
if self.producer_price_are_wo_vat:
......@@ -137,6 +242,14 @@ class Item(TranslatableModel):
else:
return '%s' % unit_price
def get_customer_alert_order_quantity(self):
if self.limit_order_quantity_to_stock:
return "%s" % _("Current stock")
return self.customer_alert_order_quantity
get_customer_alert_order_quantity.short_description = (_("customer_alert_order_quantity"))
get_customer_alert_order_quantity.allow_tags = False
def get_order_name(self, is_quantity_invoiced=False, box_unicode=BOX_UNICODE):
qty_display = self.get_qty_display(is_quantity_invoiced, box_unicode)
......@@ -166,9 +279,9 @@ class Item(TranslatableModel):
get_long_name.allow_tags = False
get_long_name.admin_order_field = 'translations__long_name'
def display(self):
def display(self, is_quantity_invoiced=False):
if self.id is not None:
return '%s, %s' % (self.producer.short_profile_name, self.get_long_name())
return '%s, %s' % (self.producer.short_profile_name, self.get_long_name(is_quantity_invoiced=is_quantity_invoiced))
else:
# Nedeed for django import export since django_import_export-0.4.5
return 'N/A'
......@@ -176,6 +289,5 @@ class Item(TranslatableModel):
def __str__(self):
return self.display()
class Meta:
abstract = True
\ No newline at end of file
# -*- coding: utf-8
from __future__ import unicode_literals
from django.conf import settings
from django.core.validators import MinValueValidator
from django.db import models
from django.db.models import F
......@@ -18,8 +17,6 @@ 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
@python_2_unicode_compatible
......@@ -41,68 +38,25 @@ class OfferItem(Item):
default=0, db_index=True)
)
permanence = models.ForeignKey(
'Permanence', verbose_name=REPANIER_SETTINGS_PERMANENCE_NAME, on_delete=models.PROTECT,
'Permanence',
verbose_name=REPANIER_SETTINGS_PERMANENCE_NAME,
on_delete=models.PROTECT,
db_index=True
)
# Important : Check select_related
product = models.ForeignKey(
'Product', verbose_name=_("product"), on_delete=models.PROTECT)
picture2 = AjaxPictureField(
verbose_name=_("picture"),
null=True, blank=True,
upload_to="product", size=SIZE_M)
reference = models.CharField(
_("reference"), max_length=36, blank=True, null=True)
department_for_customer = models.ForeignKey(
'LUT_DepartmentForCustomer',
verbose_name=_("department_for_customer"), blank=True, null=True, on_delete=models.PROTECT)
producer = models.ForeignKey(
'Producer', verbose_name=_("producer"), on_delete=models.PROTECT)
order_unit = models.CharField(
max_length=3,
choices=LUT_PRODUCT_ORDER_UNIT,
default=PRODUCT_ORDER_UNIT_PC,
verbose_name=_("order unit"))
wrapped = models.BooleanField(_('Individually wrapped by the producer'),
default=False)
order_average_weight = models.DecimalField(
_("order_average_weight"),
help_text=_('if useful, average order weight (eg : 0,1 Kg [i.e. 100 gr], 3 Kg)'),
default=DECIMAL_ZERO, max_digits=6, decimal_places=3,
validators=[MinValueValidator(0)])
placement = models.CharField(
max_length=3,
choices=LUT_PRODUCT_PLACEMENT,
default=PRODUCT_PLACEMENT_BASKET,
verbose_name=_("product_placement"),
help_text=_('used for helping to determine the order of preparation of this product'))
producer_unit_price = ModelMoneyField(
_("producer unit price"),
help_text=_('producer unit price (/piece or /kg or /l), including vat, without deposit'),
default=DECIMAL_ZERO, max_digits=8, decimal_places=2)
customer_unit_price = ModelMoneyField(
_("customer unit price"),
help_text=_('(/piece or /kg or /l), including vat, without deposit'),
default=DECIMAL_ZERO, max_digits=8, decimal_places=2)
'Product',
verbose_name=_("product"),
on_delete=models.PROTECT)
producer_price_are_wo_vat = models.BooleanField(_("producer price are wo vat"), default=False)
producer_vat = ModelMoneyField(
_("vat"),
default=DECIMAL_ZERO, max_digits=8, decimal_places=4)
customer_vat = ModelMoneyField(
_("vat"),
default=DECIMAL_ZERO, max_digits=8, decimal_places=4)
unit_deposit = ModelMoneyField(
_("deposit"),
help_text=_('deposit to add to the unit price'),
default=DECIMAL_ZERO, max_digits=8, decimal_places=2)
vat_level = models.CharField(
max_length=3,
choices=LUT_ALL_VAT, # settings.LUT_VAT,
default=settings.DICT_VAT_DEFAULT,
verbose_name=_("tax"))
price_list_multiplier = models.DecimalField(
_("price_list_multiplier"),
help_text=_("This multiplier is applied to each price automatically imported/pushed."),
default=DECIMAL_ZERO, max_digits=5, decimal_places=4,
validators=[MinValueValidator(0)])
is_resale_price_fixed = models.BooleanField(
_("the resale price is set by the producer"),
default=False)
# Calculated with Purchase
total_purchase_with_tax = ModelMoneyField(
......@@ -124,29 +78,12 @@ class OfferItem(Item):
help_text=_('quantity invoiced to our customer'),
max_digits=9, decimal_places=4, default=DECIMAL_ZERO)
is_box = models.BooleanField(_("is_box"), default=False)
is_box_content = models.BooleanField(_("is_box_content"), default=False)
# is_membership_fee = models.BooleanField(_("is_membership_fee"), default=False)
may_order = models.BooleanField(_("may_order"), default=True)
is_active = models.BooleanField(_("is_active"), default=True)
limit_order_quantity_to_stock = models.BooleanField(_("limit maximum order qty of the group to stock qty"),
default=False)
manage_replenishment = models.BooleanField(_("manage stock"), default=False)
manage_production = models.BooleanField(_("manage production"), default=False)
producer_pre_opening = models.BooleanField(_("producer pre-opening"), default=False)
price_list_multiplier = models.DecimalField(
_("price_list_multiplier"),
help_text=_("This multiplier is applied to each price automatically imported/pushed."),
default=DECIMAL_ZERO, max_digits=5, decimal_places=4,
validators=[MinValueValidator(0)])
is_resale_price_fixed = models.BooleanField(_("the resale price is set by the producer"),
default=False)
stock = models.DecimalField(
_("Current stock"),
default=DECIMAL_ZERO, max_digits=9, decimal_places=3,
validators=[MinValueValidator(0)])
add_2_stock = models.DecimalField(
_("Add 2 stock"),
default=DECIMAL_ZERO, max_digits=9, decimal_places=4)
......@@ -154,23 +91,6 @@ class OfferItem(Item):
_("Final stock"),
default=None, max_digits=9, decimal_places=3, null=True)
customer_minimum_order_quantity = models.DecimalField(
_("customer_minimum_order_quantity"),
help_text=_('minimum order qty (eg : 0,1 Kg [i.e. 100 gr], 1 piece, 3 Kg)'),
default=DECIMAL_ZERO, max_digits=6, decimal_places=3)
customer_increment_order_quantity = models.DecimalField(
_("customer_increment_order_quantity"),
help_text=_('increment order qty (eg : 0,05 Kg [i.e. 50max 1 piece, 3 Kg)'),
default=DECIMAL_ZERO, max_digits=6, decimal_places=3)
customer_alert_order_quantity = models.DecimalField(
_("customer_alert_order_quantity"),
help_text=_('maximum order qty before alerting the customer to check (eg : 1,5 Kg, 12 pieces, 9 Kg)'),
default=DECIMAL_ZERO, max_digits=6, decimal_places=3)
producer_order_by_quantity = models.DecimalField(
_("Producer order by quantity"),
help_text=_('1,5 Kg [i.e. 1500 gr], 1 piece, 3 Kg)'),
default=DECIMAL_ZERO, max_digits=6, decimal_places=3)
def get_vat_level(self):
return self.get_vat_level_display()
......@@ -318,7 +238,7 @@ def offer_item_pre_save(sender, **kwargs):
@python_2_unicode_compatible
class OfferItemSend(OfferItem):
def __str__(self):
return '%s, %s' % (self.producer.short_profile_name, self.get_long_name(is_quantity_invoiced=True))
return self.display(is_quantity_invoiced=True)
class Meta:
proxy = True
......@@ -339,7 +259,7 @@ def offer_item_send_pre_save(sender, **kwargs):
@python_2_unicode_compatible
class OfferItemClosed(OfferItem):
def __str__(self):
return '%s, %s' % (self.producer.short_profile_name, self.get_long_name(is_quantity_invoiced=True))
return self.display(is_quantity_invoiced=True)
class Meta:
proxy = True
......
......@@ -5,7 +5,6 @@ import uuid
from django.conf import settings
from django.core import urlresolvers
from django.core.validators import MinValueValidator
from django.db import models
from django.db.models import F
from django.db.models.signals import pre_save, post_save
......@@ -18,118 +17,21 @@ from parler.models import TranslatedFieldsModel
from repanier.models.item import Item
from repanier.const import *
from repanier.fields.RepanierMoneyField import ModelMoneyField
from repanier.picture.const import SIZE_M
from repanier.picture.fields import AjaxPictureField
@python_2_unicode_compatible
class Product(Item):
producer = models.ForeignKey(
'Producer', verbose_name=_("producer"), on_delete=models.PROTECT)
long_name = TranslatedField()
offer_description = TranslatedField()
production_mode = models.ManyToManyField(
'LUT_ProductionMode',
verbose_name=_("production mode"),
blank=True)
picture2 = AjaxPictureField(
verbose_name=_("picture"),
null=True, blank=True,
upload_to="product", size=SIZE_M)
reference = models.CharField(
_("reference"), max_length=36, blank=True, null=True)
department_for_customer = models.ForeignKey(
'LUT_DepartmentForCustomer', null=True, blank=True,
verbose_name=_("department_for_customer"),
on_delete=models.PROTECT)
placement = models.CharField(
max_length=3,
choices=LUT_PRODUCT_PLACEMENT,
default=PRODUCT_PLACEMENT_BASKET,
verbose_name=_("product_placement"),
help_text=_('used for helping to determine the order of preparation of this product'))
order_average_weight = models.DecimalField(
_("order_average_weight"),
help_text=_('if useful, average order weight (eg : 0,1 Kg [i.e. 100 gr], 3 Kg)'),
default=DECIMAL_ZERO, max_digits=6, decimal_places=3,
validators=[MinValueValidator(0)])
producer_unit_price = ModelMoneyField(
_("producer unit price"),
default=DECIMAL_ZERO, max_digits=8, decimal_places=2)
customer_unit_price = ModelMoneyField(
_("customer unit price"),
default=DECIMAL_ZERO, max_digits=8, decimal_places=2)
producer_vat = ModelMoneyField(
_("vat"),
default=DECIMAL_ZERO, max_digits=8, decimal_places=4)
customer_vat = ModelMoneyField(
_("vat"),
default=DECIMAL_ZERO, max_digits=8, decimal_places=4)
unit_deposit = ModelMoneyField(
_("deposit"),
help_text=_('deposit to add to the original unit price'),
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,
default=settings.DICT_VAT_DEFAULT,
verbose_name=_("tax"))
stock = models.DecimalField(
_("Current stock"),
default=DECIMAL_ZERO, max_digits=9, decimal_places=3,
validators=[MinValueValidator(0)])
limit_order_quantity_to_stock = models.BooleanField(_("limit maximum order qty of the group to stock qty"),
default=False)
customer_minimum_order_quantity = models.DecimalField(
_("customer_minimum_order_quantity"),
help_text=_('minimum order qty (eg : 0,1 Kg [i.e. 100 gr], 1 piece, 3 Kg)'),
default=DECIMAL_ONE, max_digits=6, decimal_places=3,
validators=[MinValueValidator(0)])
customer_increment_order_quantity = models.DecimalField(
_("customer_increment_order_quantity"),
help_text=_('increment order qty (eg : 0,05 Kg [i.e. 50max 1 piece, 3 Kg)'),
default=DECIMAL_ONE, max_digits=6, decimal_places=3,
validators=[MinValueValidator(0)])
customer_alert_order_quantity = models.DecimalField(
_("customer_alert_order_quantity"),
help_text=_('maximum order qty before alerting the customer to check (eg : 1,5 Kg, 12 pieces, 9 Kg)'),
default=LIMIT_ORDER_QTY_ITEM, max_digits=6, decimal_places=3,
validators=[MinValueValidator(0)])
producer_order_by_quantity = models.DecimalField(
_("Producer order by quantity"),
help_text=_('1,5 Kg [i.e. 1500 gr], 1 piece, 3 Kg)'),
default=DECIMAL_ZERO, max_digits=6, decimal_places=3,
validators=[MinValueValidator(0)])
permanences = models.ManyToManyField(
'Permanence', through='OfferItem',
blank=True)
is_into_offer = models.BooleanField(_("is_into_offer"), default=True)
likes = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='likes')
order_unit = models.CharField(
max_length=3,
choices=LUT_PRODUCT_ORDER_UNIT,
default=PRODUCT_ORDER_UNIT_PC,
verbose_name=_("order unit"),
)
wrapped = models.BooleanField(_('Individually wrapped by the producer'),
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)
......@@ -176,14 +78,6 @@ class Product(Item):
get_is_into_offer.short_description = (_("is into offer"))
get_is_into_offer.allow_tags = True
def get_customer_alert_order_quantity(self):
if self.limit_order_quantity_to_stock:
return "%s" % _("Current stock")
return self.customer_alert_order_quantity
get_customer_alert_order_quantity.short_description = (_("customer_alert_order_quantity"))
get_customer_alert_order_quantity.allow_tags = False
def __str__(self):
return super(Product, self).display()
# if self.id is not None:
......
......@@ -194,22 +194,7 @@ class Purchase(models.Model):
return self.quantity_invoiced
def get_long_name(self, customer_price=True):
if self.offer_item is not None:
if self.is_box_content:
return "%s %s" % (
self.offer_item.get_long_name(
# is_quantity_invoiced=self.status >= PERMANENCE_WAIT_FOR_SEND,