Commit d1bad61b authored by Patrick's avatar Patrick

Instroduce purchase.is_resale_price_fixed for products like crowfunding

parent ddf9683a
......@@ -237,7 +237,7 @@ class CustomerInvoice(models.Model):
result_set = purchase.Purchase.objects.filter(
permanence_id=self.permanence_id,
customer_id=self.customer_id
customer_id=self.customer_id,
).order_by('?').aggregate(
Sum('customer_vat'),
Sum('deposit'),
......@@ -257,15 +257,38 @@ class CustomerInvoice(models.Model):
self.total_price_with_tax.amount = DECIMAL_ZERO
if self.price_list_multiplier != DECIMAL_ONE:
total_price_with_tax_wo_deposit = self.total_price_with_tax.amount - self.total_deposit.amount
result_set = purchase.Purchase.objects.filter(
permanence_id=self.permanence_id,
customer_id=self.customer_id,
is_resale_price_fixed=True
).order_by('?').aggregate(
Sum('customer_vat'),
Sum('deposit'),
Sum('selling_price')
)
if result_set["customer_vat__sum"] is not None:
total_vat = result_set["customer_vat__sum"]
else:
total_vat = DECIMAL_ZERO
if result_set["deposit__sum"] is not None:
total_deposit = result_set["deposit__sum"]
else:
total_deposit = DECIMAL_ZERO
if result_set["selling_price__sum"] is not None:
total_price_with_tax = result_set["selling_price__sum"]
else:
total_price_with_tax = DECIMAL_ZERO
total_price_with_tax_wo_deposit = total_price_with_tax - total_deposit
self.delta_price_with_tax.amount = -(
total_price_with_tax_wo_deposit - (
total_price_with_tax_wo_deposit * self.price_list_multiplier
).quantize(TWO_DECIMALS)
)
self.delta_vat.amount = -(
self.total_vat - (
self.total_vat.amount * self.price_list_multiplier
total_vat - (
total_vat * self.price_list_multiplier
).quantize(FOUR_DECIMALS)
)
else:
......
......@@ -105,6 +105,8 @@ class Purchase(models.Model):
help_text=_("This multiplier is applied to each price automatically imported/pushed."),
default=DECIMAL_ONE, max_digits=5, decimal_places=4, blank=True,
validators=[MinValueValidator(0)])
is_resale_price_fixed = models.BooleanField(_("the resale price is set by the producer"),
default=False)
comment = models.CharField(
_("comment"), max_length=100, default=EMPTY_STRING, blank=True, null=True)
is_updated_on = models.DateTimeField(
......@@ -332,12 +334,14 @@ def purchase_pre_save(sender, **kwargs):
quantity = purchase.quantity_invoiced
delta_quantity = quantity - purchase.previous_quantity
if purchase.is_box_content:
purchase.is_resale_price_fixed = True
if delta_quantity != DECIMAL_ZERO:
offeritem.OfferItem.objects.filter(id=purchase.offer_item_id).update(
quantity_invoiced=F('quantity_invoiced') + delta_quantity,
)
else:
if purchase.offer_item.is_resale_price_fixed \
purchase.is_resale_price_fixed = purchase.offer_item.is_resale_price_fixed
if purchase.is_resale_price_fixed \
or purchase.offer_item.price_list_multiplier < DECIMAL_ONE:
purchase.price_list_multiplier = DECIMAL_ONE
else:
......
......@@ -1443,7 +1443,7 @@ def clean_offer_item(permanence, queryset, reset_add_2_stock=False):
offer_item.manage_production = producer.manage_production
# Important : or product.is_box -> impact into Purchase.get_customer_unit_price
# The boxes prices are not subjects to price modifications
offer_item.is_resale_price_fixed = producer.is_resale_price_fixed or product.is_box
offer_item.is_resale_price_fixed = producer.is_resale_price_fixed or product.is_box or product.order_unit >= PRODUCT_ORDER_UNIT_DEPOSIT
offer_item.price_list_multiplier = DECIMAL_ONE if offer_item.is_resale_price_fixed else producer.price_list_multiplier
offer_item.stock = product.stock
if reset_add_2_stock:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment