This commit is contained in:
Marwan Alwali 2024-12-24 18:33:17 +03:00
parent 5397363716
commit 8f59cc6723
7 changed files with 87 additions and 43 deletions

View File

@ -110,20 +110,10 @@ DATABASES = {
"NAME": "haikal", "NAME": "haikal",
"USER": "haikal", "USER": "haikal",
"PASSWORD": "haikal", "PASSWORD": "haikal",
"HOST": "localhost", "HOST": "10.10.1.120",
"PORT": 5432, "PORT": 5432,
} }
} }
# DATABASES = {
# "default": {
# "ENGINE": "django_prometheus.db.backends.postgresql",
# "NAME": "murad_haikal",
# "USER": "f95166",
# "PASSWORD": "Kfsh&rc9788",
# "HOST": "localhost",
# "PORT": 5432,
# }
# }
# Password validation # Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators

View File

@ -0,0 +1,43 @@
# Generated by Django 5.1.4 on 2024-12-24 14:43
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('inventory', '0013_salequotation_is_paid'),
]
operations = [
migrations.CreateModel(
name='Payment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('amount', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='amount')),
('payment_method', models.CharField(choices=[('cash', 'cash'), ('credit', 'credit'), ('transfer', 'transfer'), ('debit', 'debit'), ('SADAD', 'SADAD')], max_length=50, verbose_name='method')),
('reference_number', models.CharField(blank=True, max_length=100, null=True, verbose_name='reference number')),
('payment_date', models.DateField(auto_now_add=True, verbose_name='date')),
('quotation', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='payments', to='inventory.salequotation')),
],
options={
'verbose_name': 'payment',
'verbose_name_plural': 'payments',
},
),
migrations.CreateModel(
name='Refund',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('amount', models.DecimalField(decimal_places=2, max_digits=10, verbose_name='amount')),
('reason', models.TextField(blank=True, verbose_name='reason')),
('refund_date', models.DateField(auto_now_add=True, verbose_name='refund date')),
('payment', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='refund', to='inventory.payment')),
],
options={
'verbose_name': 'refund',
'verbose_name_plural': 'refunds',
},
),
]

View File

@ -1,18 +1,9 @@
from random import randint from random import randint
from django.db.models.signals import post_save, post_delete,pre_delete from django.db.models.signals import post_save, post_delete, pre_delete, pre_save
from django.dispatch import receiver from django.dispatch import receiver
from django_ledger.views import JournalEntryCreateView from django.utils import timezone
from django_ledger.models import ( from django_ledger.models import EntityModel
EntityModel,
VendorModel,
CustomerModel,
UnitOfMeasureModel,
AccountModel,
ItemModelAbstract,
ItemModel
)
from django.contrib.auth import get_user_model
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -73,25 +64,22 @@ def update_car_status_on_reservation_delete(sender, instance, **kwargs):
@receiver(post_save, sender=models.Dealer) @receiver(post_save, sender=models.Dealer)
def create_ledger_entity(sender, instance, created, **kwargs): def create_ledger_entity(sender, instance, created, **kwargs):
if created: if created:
# Group.objects.get(name=instance.dealer_type.lower()).user_set.add(instance.user) entity, created = EntityModel.objects.get_or_create(
try: name=instance.get_root_dealer.name,
entity, created = EntityModel.objects.get_or_create( admin=instance.get_root_dealer.user,
name=instance.get_root_dealer.name, # address_1=instance.address,
admin=instance.get_root_dealer.user, accrual_method=False,
# address_1=instance.address, fy_start_month=1,
accrual_method=False, depth=0,
fy_start_month=1, )
depth=0, print(entity)
) if created:
if created: default_coa = entity.create_chart_of_accounts(assign_as_default=True,
default_coa = entity.create_chart_of_accounts( commit=True,
assign_as_default=True, commit=True, coa_name=_("Chart of Accounts") coa_name=_("Chart of Accounts"))
) if default_coa:
if default_coa: entity.populate_default_coa(activate_accounts=True, coa_model=default_coa)
entity.populate_default_coa( print(f"Ledger entity created for Dealer: {instance.name}")
activate_accounts=True, coa_model=default_coa
)
print(f"Ledger entity created for Dealer: {instance.name}")
# entity.create_account( # entity.create_account(
# coa_model=coa, # coa_model=coa,
@ -156,7 +144,7 @@ def create_ledger_vendor(sender, instance, created, **kwargs):
entity = EntityModel.objects.filter(name=instance.dealer.name).first() entity = EntityModel.objects.filter(name=instance.dealer.name).first()
entity.create_vendor( entity.create_vendor(
vendor_name=instance.name, name=instance.name,
vendor_number=instance.crn, vendor_number=instance.crn,
address_1=instance.address, address_1=instance.address,
phone=instance.phone_number, phone=instance.phone_number,
@ -264,3 +252,26 @@ def create_customer(sender, instance, created, **kwargs):
# default_amount=instance.cost_price, # default_amount=instance.cost_price,
# ) # )
# print(f"Inventory item updated with CarFinance data for Car: {instance.car}") # print(f"Inventory item updated with CarFinance data for Car: {instance.car}")
@receiver(pre_save, sender=models.SaleQuotation)
def update_quotation_status(sender, instance, **kwargs):
if instance.valid_until and timezone.now() > instance.valid_until:
instance.status = 'expired'
# instance.total_price = instance.calculate_total_price()
@receiver(post_save, sender=models.Payment)
def update_status_on_payment(sender, instance, created, **kwargs):
if created:
quotation = instance.sale_quotation
total_payments = sum(payment.amount for payment in quotation.payments.all())
if total_payments >= quotation.amount:
quotation.status = 'completed'
# SalesInvoice.objects.create(sales_order=order)
elif total_payments > 0:
quotation.status = 'partially_paid'
else:
quotation.status = 'pending'
quotation.save()