Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
repanier
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chris
repanier
Commits
8975f63a
Commit
8975f63a
authored
May 06, 2017
by
Patrick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First returns
parent
f4a2f224
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
242 additions
and
133 deletions
+242
-133
repanier/admin/permanence_done.py
repanier/admin/permanence_done.py
+1
-1
repanier/admin/rule_of_3_per_customer.py
repanier/admin/rule_of_3_per_customer.py
+5
-1
repanier/management/commands/recalculate_order_amount.py
repanier/management/commands/recalculate_order_amount.py
+1
-1
repanier/management/commands/recalculate_permanences_profit.py
...ier/management/commands/recalculate_permanences_profit.py
+25
-0
repanier/models/invoice.py
repanier/models/invoice.py
+22
-27
repanier/models/permanence.py
repanier/models/permanence.py
+91
-17
repanier/models/purchase.py
repanier/models/purchase.py
+41
-48
repanier/task/task_invoice.py
repanier/task/task_invoice.py
+6
-1
repanier/tools.py
repanier/tools.py
+4
-2
repanier/views/home_info_ajax.py
repanier/views/home_info_ajax.py
+6
-2
repanier/views/login_view.py
repanier/views/login_view.py
+2
-1
repanier/views/order_class.py
repanier/views/order_class.py
+2
-1
repanier/views/order_info_ajax.py
repanier/views/order_info_ajax.py
+4
-2
repanier/xlsx/xlsx_order.py
repanier/xlsx/xlsx_order.py
+2
-2
repanier/xlsx/xlsx_purchase.py
repanier/xlsx/xlsx_purchase.py
+30
-27
No files found.
repanier/admin/permanence_done.py
View file @
8975f63a
...
...
@@ -92,7 +92,7 @@ class PermanenceDoneAdmin(TranslatableAdmin):
def
add_delivery
(
self
,
request
):
return
import_xslx_view
(
self
,
admin
,
request
,
None
,
_
(
"Import an invoice"
),
handle_uploaded_invoice
,
action
=
'
import_xlsx
'
,
form_klass
=
ImportInvoiceForm
handle_uploaded_invoice
,
action
=
'
add_delivery
'
,
form_klass
=
ImportInvoiceForm
)
def
cancel_delivery
(
self
,
request
,
permanence_qs
):
...
...
repanier/admin/rule_of_3_per_customer.py
View file @
8975f63a
...
...
@@ -42,7 +42,11 @@ class CustomerPurchaseSendInlineForm(forms.ModelForm):
super
(
CustomerPurchaseSendInlineForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
purchase
=
self
.
instance
self
.
fields
[
"previous_purchase_price"
].
initial
=
purchase
.
purchase_price
self
.
fields
[
"previous_offer_item"
].
initial
=
purchase
.
offer_item
try
:
offer_item
=
purchase
.
offer_item
except
AttributeError
:
offer_item
=
None
self
.
fields
[
"previous_offer_item"
].
initial
=
offer_item
class
Meta
:
widgets
=
{
...
...
repanier/management/commands/recalculate_order_amount.py
View file @
8975f63a
...
...
@@ -18,7 +18,7 @@ class Command(BaseCommand):
def
handle
(
self
,
*
args
,
**
options
):
recalculate_order_amount
(
permanence_id
=
60
,
permanence_id
=
32
,
re_init
=
True
)
...
...
repanier/management/commands/recalculate_permanences_profit.py
0 → 100644
View file @
8975f63a
# -*- coding: utf-8 -*-
from
django.core.management.base
import
BaseCommand
from
django.db.models
import
Sum
from
repanier.models
import
BankAccount
from
repanier.models
import
LUT_DeliveryPoint
,
DeliveryBoard
from
repanier.models
import
CustomerInvoice
,
ProducerInvoice
from
repanier.const
import
PERMANENCE_CLOSED
,
\
PERMANENCE_INVOICED
,
PERMANENCE_ARCHIVED
,
PERMANENCE_SEND
,
DECIMAL_ZERO
from
repanier.models
import
Permanence
from
repanier.tools
import
reorder_offer_items
,
recalculate_order_amount
from
repanier.task
import
task_invoice
class
Command
(
BaseCommand
):
args
=
'<none>'
help
=
'Recalculate permanence profit'
def
handle
(
self
,
*
args
,
**
options
):
for
permanence
in
Permanence
.
objects
.
filter
(
status__gte
=
PERMANENCE_CLOSED
).
order_by
(
'?'
):
print
(
"%s %s"
%
(
permanence
.
permanence_date
,
permanence
.
get_status_display
()))
permanence
.
recalculate_profit
()
permanence
.
save
()
repanier/models/invoice.py
View file @
8975f63a
...
...
@@ -24,7 +24,7 @@ def permanence_verbose_name():
if
DJANGO_IS_MIGRATION_RUNNING
:
return
EMPTY_STRING
from
repanier.apps
import
REPANIER_SETTINGS_PERMANENCE_NAME
return
lambda
:
"%s"
%
REPANIER_SETTINGS_PERMANENCE_NAME
return
_
(
'order'
)
#
lambda: "%s" % REPANIER_SETTINGS_PERMANENCE_NAME
@
python_2_unicode_compatible
...
...
@@ -115,10 +115,6 @@ class CustomerInvoice(models.Model):
help_text
=
_
(
"This is the minimum order amount to avoid shipping cost."
),
default
=
DECIMAL_ZERO
,
max_digits
=
5
,
decimal_places
=
2
,
validators
=
[
MinValueValidator
(
0
)])
# customer_charged = models.ForeignKey(
# 'Customer', verbose_name=_("customer"),
# related_name='invoices_paid',
# on_delete=models.PROTECT, db_index=True)
master_permanence
=
models
.
ForeignKey
(
'Permanence'
,
verbose_name
=
_
(
"master permanence"
),
related_name
=
'child_customer_invoice'
,
...
...
@@ -205,34 +201,33 @@ class CustomerInvoice(models.Model):
self
.
calculate_and_save_delta_buyinggroup
(
confirm_order
=
True
)
self
.
is_order_confirm_send
=
True
@
transaction
.
atomic
def
calculate_and_save_delta_buyinggroup
(
self
,
confirm_order
=
False
):
producer_invoice_buyinggroup
=
ProducerInvoice
.
objects
.
filter
(
producer__represent_this_buyinggroup
=
True
,
permanence_id
=
self
.
permanence_id
,
).
order_by
(
'?'
).
first
()
if
producer_invoice_buyinggroup
is
None
:
producer_buyinggroup
=
producer
.
Producer
.
objects
.
filter
(
represent_this_buyinggroup
=
True
).
order_by
(
'?'
).
first
()
producer_invoice_buyinggroup
=
ProducerInvoice
.
objects
.
create
(
producer_id
=
producer_buyinggroup
.
id
,
permanence_id
=
self
.
permanence_id
,
status
=
self
.
permanence
.
status
)
else
:
producer_invoice_buyinggroup
.
delta_price_with_tax
.
amount
-=
self
.
delta_price_with_tax
.
amount
producer_invoice_buyinggroup
.
delta_vat
.
amount
-=
self
.
delta_vat
.
amount
producer_invoice_buyinggroup
.
delta_transport
.
amount
-=
self
.
delta_transport
.
amount
previous_delta_price_with_tax
=
self
.
delta_price_with_tax
.
amount
previous_delta_vat
=
self
.
delta_vat
.
amount
previous_delta_transport
=
self
.
delta_transport
.
amount
self
.
calculate_delta_price
(
confirm_order
)
self
.
calculate_delta_transport
()
producer_invoice_buyinggroup
.
delta_price_with_tax
.
amount
+=
self
.
delta_price_with_tax
.
amount
producer_invoice_buyinggroup
.
delta_vat
.
amount
+=
self
.
delta_vat
.
amount
producer_invoice_buyinggroup
.
delta_transport
.
amount
+=
self
.
delta_transport
.
amount
if
previous_delta_price_with_tax
!=
self
.
delta_price_with_tax
.
amount
or
previous_delta_vat
!=
self
.
delta_vat
.
amount
or
previous_delta_transport
!=
self
.
delta_transport
.
amount
:
producer_invoice_buyinggroup
=
ProducerInvoice
.
objects
.
filter
(
producer__represent_this_buyinggroup
=
True
,
permanence_id
=
self
.
permanence_id
,
).
order_by
(
'?'
).
first
()
if
producer_invoice_buyinggroup
is
None
:
producer_buyinggroup
=
producer
.
Producer
.
objects
.
filter
(
represent_this_buyinggroup
=
True
).
order_by
(
'?'
).
first
()
producer_invoice_buyinggroup
=
ProducerInvoice
.
objects
.
create
(
producer_id
=
producer_buyinggroup
.
id
,
permanence_id
=
self
.
permanence_id
,
status
=
self
.
permanence
.
status
)
producer_invoice_buyinggroup
.
delta_price_with_tax
.
amount
+=
self
.
delta_price_with_tax
.
amount
-
previous_delta_price_with_tax
producer_invoice_buyinggroup
.
delta_vat
.
amount
+=
self
.
delta_vat
.
amount
-
previous_delta_vat
producer_invoice_buyinggroup
.
delta_transport
.
amount
+=
self
.
delta_transport
.
amount
-
previous_delta_transport
producer_invoice_buyinggroup
.
save
()
producer_invoice_buyinggroup
.
save
()
def
calculate_delta_price
(
self
,
confirm_order
=
False
):
getcontext
().
rounding
=
ROUND_HALF_UP
...
...
repanier/models/permanence.py
View file @
8975f63a
...
...
@@ -7,7 +7,7 @@ from django.conf import settings
from
django.core
import
urlresolvers
from
django.core.cache
import
cache
from
django.db
import
models
from
django.db.models
import
F
from
django.db.models
import
F
,
Sum
from
django.utils
import
timezone
,
translation
from
django.utils.encoding
import
python_2_unicode_compatible
from
django.utils.formats
import
number_format
...
...
@@ -101,11 +101,28 @@ class Permanence(TranslatableModel):
verbose_name
=
_
(
"producers"
),
blank
=
True
)
total_price_wo_tax
=
ModelMoneyField
(
# Calculated with Purchase
invoiced_with_tax
=
ModelMoneyField
(
_
(
"Total amount"
),
help_text
=
_
(
'Total purchase amount vat
ex
cluded'
),
help_text
=
_
(
'Total purchase amount vat
in
cluded'
),
default
=
DECIMAL_ZERO
,
max_digits
=
8
,
decimal_places
=
2
)
total_profit
=
ModelMoneyField
(
vat
=
ModelMoneyField
(
_
(
"Total vat"
),
help_text
=
_
(
'Vat part of the total purchased'
),
default
=
DECIMAL_ZERO
,
max_digits
=
9
,
decimal_places
=
4
)
deposit
=
ModelMoneyField
(
_
(
"deposit"
),
help_text
=
_
(
'deposit to add to the original unit price'
),
default
=
DECIMAL_ZERO
,
max_digits
=
8
,
decimal_places
=
2
)
transport
=
ModelMoneyField
(
_
(
"Delivery point transport"
),
help_text
=
_
(
"transport to add"
),
default
=
DECIMAL_ZERO
,
max_digits
=
5
,
decimal_places
=
2
)
# total_price_wo_tax = ModelMoneyField(
# _("Total amount"),
# help_text=_('Total purchase amount vat excluded'),
# default=DECIMAL_ZERO, max_digits=8, decimal_places=2)
profit
=
ModelMoneyField
(
_
(
"Total profit"
),
help_text
=
_
(
'Total profit'
),
default
=
DECIMAL_ZERO
,
max_digits
=
8
,
decimal_places
=
2
)
...
...
@@ -575,6 +592,65 @@ class Permanence(TranslatableModel):
cur_language
=
translation
.
get_language
(),
)
def
recalculate_profit
(
self
):
result_set
=
invoice
.
CustomerInvoice
.
objects
.
filter
(
permanence_id
=
self
.
id
).
order_by
(
'?'
).
aggregate
(
Sum
(
'total_price_with_tax'
),
Sum
(
'delta_price_with_tax'
),
Sum
(
'total_vat'
),
Sum
(
'delta_vat'
),
Sum
(
'total_deposit'
),
Sum
(
'delta_transport'
)
)
if
result_set
[
"total_price_with_tax__sum"
]
is
not
None
:
ci_sum_total_price_with_tax
=
result_set
[
"total_price_with_tax__sum"
]
else
:
ci_sum_total_price_with_tax
=
DECIMAL_ZERO
if
result_set
[
"delta_price_with_tax__sum"
]
is
not
None
:
ci_sum_delta_price_with_tax
=
result_set
[
"delta_price_with_tax__sum"
]
else
:
ci_sum_delta_price_with_tax
=
DECIMAL_ZERO
if
result_set
[
"total_vat__sum"
]
is
not
None
:
ci_sum_total_vat
=
result_set
[
"total_vat__sum"
]
else
:
ci_sum_total_vat
=
DECIMAL_ZERO
if
result_set
[
"delta_vat__sum"
]
is
not
None
:
ci_sum_delta_vat
=
result_set
[
"delta_vat__sum"
]
else
:
ci_sum_delta_vat
=
DECIMAL_ZERO
if
result_set
[
"total_deposit__sum"
]
is
not
None
:
ci_sum_total_deposit
=
result_set
[
"total_deposit__sum"
]
else
:
ci_sum_total_deposit
=
DECIMAL_ZERO
if
result_set
[
"delta_transport__sum"
]
is
not
None
:
ci_sum_delta_transport
=
result_set
[
"delta_transport__sum"
]
else
:
ci_sum_delta_transport
=
DECIMAL_ZERO
self
.
invoiced_with_tax
.
amount
=
ci_sum_total_price_with_tax
+
ci_sum_delta_price_with_tax
+
ci_sum_delta_transport
self
.
vat
.
amount
=
ci_sum_total_vat
+
ci_sum_delta_vat
self
.
deposit
.
amount
=
ci_sum_total_deposit
result_set
=
invoice
.
ProducerInvoice
.
objects
.
filter
(
permanence_id
=
self
.
id
).
order_by
(
'?'
).
aggregate
(
Sum
(
'total_price_with_tax'
),
Sum
(
'total_vat'
),
Sum
(
'total_deposit'
)
)
if
result_set
[
"total_price_with_tax__sum"
]
is
not
None
:
pi_sum_total_price_with_tax
=
result_set
[
"total_price_with_tax__sum"
]
else
:
pi_sum_total_price_with_tax
=
DECIMAL_ZERO
if
result_set
[
"total_vat__sum"
]
is
not
None
:
pi_sum_total_vat
=
result_set
[
"total_vat__sum"
]
else
:
pi_sum_total_vat
=
DECIMAL_ZERO
if
result_set
[
"total_deposit__sum"
]
is
not
None
:
pi_sum_total_deposit
=
result_set
[
"total_deposit__sum"
]
else
:
pi_sum_total_deposit
=
DECIMAL_ZERO
self
.
profit
.
amount
=
self
.
invoiced_with_tax
.
amount
-
pi_sum_total_price_with_tax
-
self
.
vat
.
amount
+
pi_sum_total_vat
def
get_full_status_display
(
self
):
return
get_full_status_display
(
self
)
...
...
@@ -595,20 +671,18 @@ class Permanence(TranslatableModel):
return
permanence_display
def
get_permanence_admin_display
(
self
):
if
self
.
total_price_wo_tax
!=
DECIMAL_ZERO
:
if
self
.
total_profit
.
amount
!=
DECIMAL_ZERO
:
return
'%s<br/>%s %s<br/>৺ %s<br/>%s%%'
%
(
self
.
get_permanence_display
(),
_
(
'wo tax'
),
self
.
total_price_wo_tax
,
self
.
total_profit
,
number_format
((
self
.
total_profit
.
amount
/
self
.
total_price_wo_tax
.
amount
)
*
100
,
2
)
)
else
:
return
'%s<br/>%s %s'
%
(
self
.
get_permanence_display
(),
_
(
'wo tax'
),
self
.
total_price_wo_tax
)
if
self
.
invoiced_with_tax
.
amount
!=
DECIMAL_ZERO
:
if
self
.
profit
.
amount
!=
DECIMAL_ZERO
:
invoiced_wo_tax
=
self
.
invoiced_with_tax
.
amount
-
self
.
vat
.
amount
if
invoiced_wo_tax
!=
DECIMAL_ZERO
:
return
'%s<br/>%s<br/>৺ %s<br/>%s%%'
%
(
self
.
get_permanence_display
(),
self
.
invoiced_with_tax
,
self
.
profit
,
number_format
((
self
.
profit
.
amount
/
invoiced_wo_tax
)
*
100
,
2
)
)
return
'%s<br/>%s'
%
(
self
.
get_permanence_display
(),
self
.
invoiced_with_tax
)
else
:
if
self
.
total_profit
.
amount
!=
DECIMAL_ZERO
:
return
'%s<br/>%s ৺ %s'
%
(
self
.
get_permanence_display
(),
_
(
'wo tax'
),
self
.
total_profit
)
else
:
return
self
.
get_permanence_display
()
return
self
.
get_permanence_display
()
get_permanence_admin_display
.
short_description
=
lambda
:
"%s"
%
repanier
.
apps
.
REPANIER_SETTINGS_PERMANENCES_NAME
get_permanence_admin_display
.
allow_tags
=
True
...
...
repanier/models/purchase.py
View file @
8975f63a
...
...
@@ -109,13 +109,13 @@ class Purchase(models.Model):
is_updated_on
=
models
.
DateTimeField
(
_
(
"is_updated_on"
),
auto_now
=
True
,
db_index
=
True
)
def
get_customer_unit_price
(
self
,
with_price_list_multiplier
=
True
):
def
get_customer_unit_price
(
self
):
offer_item
=
self
.
offer_item
customer_unit_price
=
offer_item
.
customer_unit_price
.
amount
if
self
.
price_list_multiplier
==
DECIMAL_ONE
or
not
with_price_list_multiplier
:
return
customer_unit_price
if
self
.
price_list_multiplier
==
DECIMAL_ONE
:
return
offer_item
.
customer_unit_price
.
amount
else
:
return
(
customer_unit_price
*
self
.
price_list_multiplier
).
quantize
(
TWO_DECIMALS
)
getcontext
().
rounding
=
ROUND_HALF_UP
return
(
offer_item
.
customer_unit_price
.
amount
*
self
.
price_list_multiplier
).
quantize
(
TWO_DECIMALS
)
get_customer_unit_price
.
short_description
=
(
_
(
"customer unit price"
))
get_customer_unit_price
.
allow_tags
=
False
...
...
@@ -124,18 +124,18 @@ class Purchase(models.Model):
return
self
.
offer_item
.
unit_deposit
.
amount
def
get_customer_unit_vat
(
self
):
offer_item
=
self
.
offer_item
if
self
.
price_list_multiplier
==
DECIMAL_ONE
:
return
self
.
offer_item
.
customer_vat
.
amount
return
offer_item
.
customer_vat
.
amount
else
:
getcontext
().
rounding
=
ROUND_HALF_UP
return
(
self
.
offer_item
.
customer_vat
.
amount
*
self
.
price_list_multiplier
).
quantize
(
FOUR_DECIMALS
)
return
(
offer_item
.
customer_vat
.
amount
*
self
.
price_list_multiplier
).
quantize
(
FOUR_DECIMALS
)
def
get_producer_unit_vat
(
self
):
if
self
.
price_list_multiplier
==
DECIMAL_ONE
:
return
self
.
offer_item
.
producer_vat
.
amount
else
:
getcontext
().
rounding
=
ROUND_HALF_UP
return
(
self
.
offer_item
.
producer_vat
.
amount
*
self
.
price_list_multiplier
).
quantize
(
FOUR_DECIMALS
)
offer_item
=
self
.
offer_item
if
offer_item
.
manage_production
:
return
self
.
get_customer_unit_vat
()
return
offer_item
.
producer_vat
.
amount
def
get_selling_price
(
self
):
# workaround for a display problem with Money field in the admin list_display
...
...
@@ -144,10 +144,10 @@ class Purchase(models.Model):
get_selling_price
.
short_description
=
(
_
(
"customer row price"
))
get_selling_price
.
allow_tags
=
False
def
get_producer_unit_price
(
self
,
with_price_list_multiplier
=
True
):
def
get_producer_unit_price
(
self
):
offer_item
=
self
.
offer_item
if
offer_item
.
manage_production
:
return
self
.
get_customer_unit_price
(
with_price_list_multiplier
)
return
self
.
get_customer_unit_price
()
return
offer_item
.
producer_unit_price
.
amount
get_producer_unit_price
.
short_description
=
(
_
(
"producer unit price"
))
...
...
@@ -366,14 +366,14 @@ def purchase_pre_save(sender, **kwargs):
purchase
.
price_list_multiplier
=
DECIMAL_ONE
else
:
purchase
.
price_list_multiplier
=
purchase
.
customer
.
price_list_multiplier
producer_unit_price
=
purchase
.
get_producer_unit_price
()
customer_unit_price
=
purchase
.
get_customer_unit_price
()
unit_deposit
=
purchase
.
get_unit_deposit
()
purchase
.
purchase_price
.
amount
=
(
(
p
roducer_unit_price
+
unit_deposit
)
*
quantity
).
quantize
(
TWO_DECIMALS
)
(
p
urchase
.
get_producer_unit_price
()
+
unit_deposit
)
*
quantity
).
quantize
(
TWO_DECIMALS
)
purchase
.
selling_price
.
amount
=
(
(
customer_unit_price
+
unit_deposit
)
*
quantity
).
quantize
(
TWO_DECIMALS
)
(
purchase
.
get_customer_unit_price
()
+
unit_deposit
)
*
quantity
).
quantize
(
TWO_DECIMALS
)
delta_purchase_price
=
purchase
.
purchase_price
.
amount
-
purchase
.
previous_purchase_price
delta_selling_price
=
purchase
.
selling_price
.
amount
-
purchase
.
previous_selling_price
...
...
@@ -382,53 +382,46 @@ def purchase_pre_save(sender, **kwargs):
delta_purchase_price
!=
DECIMAL_ZERO
):
purchase
.
vat_level
=
purchase
.
offer_item
.
vat_level
purchase
.
producer_vat
.
amount
=
purchase
.
get_producer_unit_vat
()
*
quantity
purchase
.
customer_vat
.
amount
=
purchase
.
get_customer_unit_vat
()
*
quantity
purchase
.
producer_vat
.
amount
=
(
purchase
.
get_producer_unit_vat
()
*
quantity
).
quantize
(
FOUR_DECIMALS
)
purchase
.
customer_vat
.
amount
=
(
purchase
.
get_customer_unit_vat
()
*
quantity
).
quantize
(
FOUR_DECIMALS
)
purchase
.
deposit
.
amount
=
unit_deposit
*
quantity
delta_p
roducer
_vat
=
purchase
.
producer_vat
.
amount
-
purchase
.
previous_producer_vat
delta_
customer
_vat
=
purchase
.
customer_vat
.
amount
-
purchase
.
previous_customer_vat
delta_p
urchase
_vat
=
purchase
.
producer_vat
.
amount
-
purchase
.
previous_producer_vat
delta_
selling
_vat
=
purchase
.
customer_vat
.
amount
-
purchase
.
previous_customer_vat
delta_deposit
=
purchase
.
deposit
.
amount
-
purchase
.
previous_deposit
offeritem
.
OfferItem
.
objects
.
filter
(
id
=
purchase
.
offer_item_id
).
update
(
quantity_invoiced
=
F
(
'quantity_invoiced'
)
+
delta_quantity
,
total_purchase_with_tax
=
F
(
'total_purchase_with_tax'
)
+
delta_purchase_price
,
total_selling_with_tax
=
F
(
'total_selling_with_tax'
)
+
delta_selling_price
quantity_invoiced
=
F
(
'quantity_invoiced'
)
+
delta_quantity
,
total_purchase_with_tax
=
F
(
'total_purchase_with_tax'
)
+
delta_purchase_price
,
total_selling_with_tax
=
F
(
'total_selling_with_tax'
)
+
delta_selling_price
)
purchase
.
offer_item
=
offeritem
.
OfferItem
.
objects
.
filter
(
id
=
purchase
.
offer_item_id
).
order_by
(
'?'
).
first
()
invoice
.
CustomerInvoice
.
objects
.
filter
(
id
=
purchase
.
customer_invoice
.
id
).
update
(
total_price_with_tax
=
F
(
'total_price_with_tax'
)
+
delta_selling_price
,
total_vat
=
F
(
'total_vat'
)
+
delta_customer_vat
,
total_price_with_tax
=
F
(
'total_price_with_tax'
)
+
delta_selling_price
,
total_vat
=
F
(
'total_vat'
)
+
delta_selling_vat
,
total_deposit
=
F
(
'total_deposit'
)
+
delta_deposit
)
invoice
.
CustomerProducerInvoice
.
objects
.
filter
(
id
=
purchase
.
customer_producer_invoice_id
).
update
(
total_purchase_with_tax
=
F
(
'total_purchase_with_tax'
)
+
delta_purchase_price
,
total_selling_with_tax
=
F
(
'total_selling_with_tax'
)
+
delta_selling_price
total_purchase_with_tax
=
F
(
'total_purchase_with_tax'
)
+
delta_purchase_price
,
total_selling_with_tax
=
F
(
'total_selling_with_tax'
)
+
delta_selling_price
)
if
purchase
.
offer_item
.
price_list_multiplier
<=
DECIMAL_ONE
and
not
purchase
.
offer_item
.
is_resale_price_fixed
:
delta_total_price_with_tax
=
delta_selling_price
delta_total_vat
=
delta_customer_vat
delta_profit
=
DECIMAL_ZERO
else
:
delta_total_price_with_tax
=
delta_purchase_price
delta_total_vat
=
delta_producer_vat
delta_profit
=
delta_selling_price
-
delta_purchase_price
-
delta_customer_vat
+
delta_producer_vat
delta_purchase_price
=
delta_selling_price
delta_purchase_vat
=
delta_selling_vat
invoice
.
ProducerInvoice
.
objects
.
filter
(
id
=
purchase
.
producer_invoice_id
).
update
(
total_price_with_tax
=
F
(
'total_price_with_tax'
)
+
delta_total_price_with_tax
,
total_vat
=
F
(
'total_vat'
)
+
delta_total_vat
,
total_price_with_tax
=
F
(
'total_price_with_tax'
)
+
delta_purchase_price
,
total_vat
=
F
(
'total_vat'
)
+
delta_purchase_vat
,
total_deposit
=
F
(
'total_deposit'
)
+
delta_deposit
)
delta_profit
=
delta_selling_price
-
delta_purchase_price
-
delta_selling_vat
+
delta_purchase_vat
permanence
.
Permanence
.
objects
.
filter
(
id
=
purchase
.
permanence_id
).
update
(
total_price_wo_tax
=
F
(
'total_price_wo_tax'
)
+
delta_total_price_with_tax
-
delta_total_vat
,
total_profit
=
F
(
'total_profit'
)
+
delta_profit
invoiced_with_tax
=
F
(
'invoiced_with_tax'
)
+
delta_selling_price
,
vat
=
F
(
'vat'
)
+
delta_selling_vat
,
deposit
=
F
(
'deposit'
)
+
delta_deposit
,
profit
=
F
(
'profit'
)
+
delta_profit
)
# Do not do it twice
purchase
.
previous_quantity_ordered
=
purchase
.
quantity_ordered
...
...
repanier/task/task_invoice.py
View file @
8975f63a
...
...
@@ -103,6 +103,10 @@ def generate_invoice(permanence, payment_date):
customer_invoice_id
=
new_customer_invoice
.
id
,
customer_charged_id
=
new_customer_invoice
.
customer_charged_id
)
recalculate_order_amount
(
permanence_id
=
new_permanence
.
id
,
re_init
=
True
)
# Important : linked to task_invoice.cancel
# First pass, set customer_charged
...
...
@@ -163,7 +167,8 @@ def generate_invoice(permanence, payment_date):
)
customer
.
save
(
update_fields
=
[
'membership_fee_valid_until'
,
])
permanence
.
recalculate_profit
()
permanence
.
save
()
for
customer_invoice
in
CustomerInvoice
.
objects
.
filter
(
permanence_id
=
permanence
.
id
...
...
repanier/tools.py
View file @
8975f63a
...
...
@@ -752,8 +752,10 @@ def recalculate_order_amount(permanence_id,
models
.
Permanence
.
objects
.
filter
(
id
=
permanence_id
).
update
(
total_profit
=
DECIMAL_ZERO
,
total_price_wo_tax
=
DECIMAL_ZERO
invoiced_with_tax
=
DECIMAL_ZERO
,
vat
=
DECIMAL_ZERO
,
deposit
=
DECIMAL_ZERO
,
profit
=
DECIMAL_ZERO
)
for
offer_item
in
models
.
OfferItem
.
objects
.
filter
(
permanence_id
=
permanence_id
,
...
...
repanier/views/home_info_ajax.py
View file @
8975f63a
...
...
@@ -9,6 +9,7 @@ from django.utils.html import format_html
from
django.utils.safestring
import
mark_safe
from
django.views.decorators.cache
import
never_cache
from
django.views.decorators.http
import
require_GET
from
parler.models
import
TranslationDoesNotExist
from
repanier.const
import
PERMANENCE_OPENED
,
EMPTY_STRING
from
repanier.models
import
Permanence
...
...
@@ -65,7 +66,10 @@ def home_info_ajax(request):
"""
.
format
(
permanences
=
""
.
join
(
permanences
)
)
if
REPANIER_SETTINGS_CONFIG
.
notification
:
notification
=
REPANIER_SETTINGS_CONFIG
.
safe_translation_getter
(
'notification'
,
any_language
=
True
,
default
=
EMPTY_STRING
)
if
notification
:
if
REPANIER_SETTINGS_CONFIG
.
notification_is_public
or
request
.
user
.
is_authenticated
:
home_info
=
"""
<div class="container">
...
...
@@ -81,7 +85,7 @@ def home_info_ajax(request):
</div>
{home_info}
"""
.
format
(
notification
=
REPANIER_SETTINGS_CONFIG
.
notification
,
notification
=
notification
,
home_info
=
home_info
)
...
...
repanier/views/login_view.py
View file @
8975f63a
...
...
@@ -52,7 +52,8 @@ def login_view(request, template_name='repanier/registration/login.html',
redirect_field_name
:
redirect_to
,
'site'
:
current_site
,
'site_name'
:
current_site
.
name
,
'how_to_register'
:
REPANIER_SETTINGS_CONFIG
.
how_to_register
'how_to_register'
:
REPANIER_SETTINGS_CONFIG
.
safe_translation_getter
(
'how_to_register'
,
any_language
=
True
,
default
=
EMPTY_STRING
)
}
if
extra_context
is
not
None
:
context
.
update
(
extra_context
)
...
...
repanier/views/order_class.py
View file @
8975f63a
...
...
@@ -143,7 +143,8 @@ class OrderView(ListView):
context
[
'q'
]
=
self
.
q
context
[
'is_anonymous'
]
=
self
.
is_anonymous
if
self
.
is_anonymous
:
context
[
'how_to_register'
]
=
REPANIER_SETTINGS_CONFIG
.
how_to_register
context
[
'how_to_register'
]
=
REPANIER_SETTINGS_CONFIG
.
safe_translation_getter
(
'how_to_register'
,
any_language
=
True
,
default
=
EMPTY_STRING
)
else
:
context
[
'how_to_register'
]
=
EMPTY_STRING
context
[
'may_order'
]
=
self
.
may_order
...
...
repanier/views/order_info_ajax.py
View file @
8975f63a
...
...
@@ -20,7 +20,9 @@ def order_info_ajax(request):
if
request
.
is_ajax
():
from
repanier.apps
import
REPANIER_SETTINGS_CONFIG
order_info
=
EMPTY_STRING
if
REPANIER_SETTINGS_CONFIG
.
notification
:
notification
=
REPANIER_SETTINGS_CONFIG
.
safe_translation_getter
(
'notification'
,
any_language
=
True
,
default
=
EMPTY_STRING
)
if
notification
:
if
REPANIER_SETTINGS_CONFIG
.
notification_is_public
or
request
.
user
.
is_authenticated
:
order_info
=
"""
<div class="row">
...
...
@@ -35,7 +37,7 @@ def order_info_ajax(request):
</div>
</div>
"""
.
format
(
notification
=
REPANIER_SETTINGS_CONFIG
.
notification
notification
=
notification
)
return
HttpResponse
(
order_info
)
...
...
repanier/xlsx/xlsx_order.py
View file @
8975f63a
...
...
@@ -1067,8 +1067,8 @@ def export_producer_by_customer(permanence, producer, wb=None):
if
first_purchase
:
first_purchase
=
False
c
=
ws
.
cell
(
row
=
row_num
,
column
=
4
)
producer_unit_price
=
purchase
.
get_producer_unit_price
(
with_price_list_multiplier
=
False
)
customer_unit_price
=
purchase
.
get_customer_unit_price
(
with_price_list_multiplier
=
False
)
producer_unit_price
=
purchase
.
get_producer_unit_price
()
customer_unit_price
=
purchase
.
get_customer_unit_price
()
if
producer_unit_price
<
customer_unit_price
:
unit_price
=
producer_unit_price
else
:
...
...
repanier/xlsx/xlsx_purchase.py
View file @
8975f63a
...
...
@@ -198,6 +198,8 @@ def export_purchase(permanence=None, year=None, producer=None, customer=None, wb
c
=
ws
.
cell
(
row
=
row_num
,
column
=
7
)
c
.
value
=
purchase
.
get_producer_unit_price
()
c
.
style
.
number_format
.
format_code
=
REPANIER_SETTINGS_CURRENCY_XLSX
if
year
is
None
:
c
.
style
.
font
.
color
=
Color
(
Color
.
BLUE
)
c
=
ws
.
cell
(
row
=
row_num
,
column
=
8
)
c
.
value
=
purchase
.
offer_item
.
unit_deposit
.
amount
c
.
style
.
number_format
.
format_code
=
REPANIER_SETTINGS_CURRENCY_XLSX
...
...
@@ -591,13 +593,15 @@ def import_purchase_sheet(worksheet, permanence=None,
error_msg
=
_
(
"Row %(row_num)d : No valid customer"
)
%
{
'row_num'
:
row_num
+
1
}
break
comment
=
cap
(
row
[
_
(
'comment'
)],
100
)
quantity_invoiced
=
DECIMAL_ZERO
if
row
[
_
(
'quantity invoiced'
)]
is
None
\
else
Decimal
(
row
[
_
(
'quantity invoiced'
)]).
quantize
(
FOUR_DECIMALS
)
producer_row_price
=
row
[
_
(
'purchase price'
)]
producer_unit_price
=
purchase
.
offer_item
.
producer_unit_price
.
amount
if
row
[
_
(
'producer unit price'
)]
is
None
\
else
Decimal
(
row
[
_
(
'producer unit price'
)]).
quantize
(
TWO_DECIMALS
)
producer_row_price
=
DECIMAL_ZERO
if
row
[
_
(
'purchase price'
)]
is
None
\
else
Decimal
(
row
[
_
(
'purchase price'
)]).
quantize
(
TWO_DECIMALS
)
if
producer_row_price
is
not
None
:
producer_row_price
=
Decimal
(
producer_row_price
).
quantize
(
TWO_DECIMALS
)
if
purchase
.
purchase_price
.
amount
!=
producer_row_price
:
purchase_price_modified
=
True
if
purchase
.
offer_item
.
order_unit
in
[
PRODUCT_ORDER_UNIT_KG
,
PRODUCT_ORDER_UNIT_PC_KG
,
PRODUCT_ORDER_UNIT_LT
...
...
@@ -609,33 +613,32 @@ def import_purchase_sheet(worksheet, permanence=None,
producer_unit_price
).
quantize
(
FOUR_DECIMALS
)
else
:
purchase
.
quantity_invoiced
=
DECIMAL_ZERO
else
:
purchase_price_modified
=
False
elif
purchase
.
quantity_invoiced
!=
quantity_invoiced
:
quantity_invoiced
=
DECIMAL_ZERO
if
row
[
_
(
'quantity invoiced'
)]
is
None
\
else
Decimal
(
row
[
_
(
'quantity invoiced'
)]).
quantize
(
FOUR_DECIMALS
)
if
purchase
.
quantity_invoiced
!=
quantity_invoiced
:
purchase
.
quantity_invoiced
=
quantity_invoiced
purchase_price_modified
=
False
else
:
purchase_price_modified
=
False
if
row_format
==
"A"
:
array_purchase
=
[]
rule_of_3_source
=
DECIMAL_ZERO
if
not
purchase_price_modified
:
producer_unit_price
=
Decimal
(
row
[
_
(
'producer unit price'
)]).
quantize
(
TWO_DECIMALS
)
previous_producer_unit_price
=
purchase
.
get_producer_unit_price
()
if
producer_unit_price
!=
previous_producer_unit_price
:
offer_item
=
OfferItem
.
objects
.
filter
(
id
=
purchase
.
offer_item_id
).
order_by
(
'?'
).
first
()
offer_item
.
producer_unit_price
=
producer_unit_price
recalculate_prices
(
offer_item
,
offer_item
.
producer_price_are_wo_vat
,
offer_item
.
is_resale_price_fixed
,
offer_item
.
price_list_multiplier
)
offer_item
.
save
()
recalculate_order_amount
(
permanence_id
=
offer_item
.
permanence_id
,
offer_item_qs
=
OfferItem
.
objects
.
filter
(
id
=
offer_item
.
id
).
order_by
(
'?'
),
)
purchase
.
comment
=
comment
purchase
.
save
()
rule_of_3_source
+=
purchase
.
purchase_price
.
amount
if
row_format
==
"A"
:
array_purchase
=
[]
rule_of_3_source
=
DECIMAL_ZERO
previous_producer_unit_price
=
purchase
.
get_producer_unit_price
()
if
producer_unit_price
!=
previous_producer_unit_price
:
offer_item
=
OfferItem
.
objects
.
filter
(
id
=
purchase
.
offer_item_id
).
order_by
(
'?'
).
first
()
offer_item
.
producer_unit_price
=
producer_unit_price
recalculate_prices
(
offer_item
,
offer_item
.
producer_price_are_wo_vat
,
offer_item
.
is_resale_price_fixed
,
offer_item
.
price_list_multiplier
)
offer_item
.
save
()