Skip to content

Instantly share code, notes, and snippets.

@happychallenge
Last active February 7, 2019 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save happychallenge/8c5e994f9e4d5c39fa51f5fe3266c32d to your computer and use it in GitHub Desktop.
Save happychallenge/8c5e994f9e4d5c39fa51f5fe3266c32d to your computer and use it in GitHub Desktop.
{% load humanize %}
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th width="20%">COST TYPE</th>
<th width="15%">CURRENCY</th>
<th width="45%">CONTENT</th>
<th width="20%">AMOUNT</th>
</tr>
</thead>
<tbody>
{% regroup service.get_costs by ctype as costtypes %}
{% for costtype in costtypes %}
{% regroup costtype.list by currency as monytypes %}
{% for money in monytypes %}
{% for cost in money.list %}
<tr>
구분 : {{ costtype.grouper }} <br>
{% ifchanged costtype.grouper %}
<td rowspan="{{ costtype.list|length }}"> {{costtype.grouper}} </td>
{% endifchanged %}
&nbsp;&nbsp;&nbsp; 화폐 {{money.grouper}} <br>
{% ifchanged money.grouper %}
<td rowspan="{{ money.list|length }}"> {{money.grouper}} </td>
{% endifchanged %}
<td>
{{cost.content }}
{% if cost.author == user %}
<button class="btn btn-warning btn-xs pull-right" id="btn-cost-edit"
data-url="{% url 'fta:service_cost_edit' cost.id %}"
>edit</button>
{% endif %}
</td>
<td align="right"> {{cost.cost|intcomma}} </td>
</tr>
{% endfor %}
{% endfor %}
{% endfor %}
</tbody>
</table>
{% load humanize %}
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th width="20%">COST TYPE</th>
<th width="15%">CURRENCY</th>
<th width="45%">CONTENT</th>
<th width="20%">AMOUNT</th>
</tr>
</thead>
<tbody>
{% regroup service.get_costs by ctype as ctypes %}
{% for ctype in ctypes %}
{% for cost in ctype.list %}
<tr>
{% ifchanged ctype %}
<td rowspan="{{ ctype.list|length }}"> {{ctype.grouper}} </td>
{% endifchanged %}
<td> {{cost.currency}} </td>
<td>
{{cost.content }}
{% if cost.author == user %}
<button class="btn btn-warning btn-xs pull-right" id="btn-cost-edit"
data-url="{% url 'fta:service_cost_edit' cost.id %}"
>edit</button>
{% endif %}
</td>
<td align="right"> {{cost.cost|intcomma}} </td>
</tr>
{% endfor %}
{% endfor %}
</tbody>
</table>
class Service(models.Model):
REWORK = '재작업'
CUSTOMER = '고객요청'
MAINTENANCE = '하자보완'
ADDITIONAL = '추가작업'
ASTYPE = (
(MAINTENANCE, '하자보완'),
(REWORK, '재작업'),
(CUSTOMER, '고객요청'),
(ADDITIONAL, '추가작업'),
)
ACCEPT = 'AS 접수'
TEAMASSIGNED = '팀 할당'
SITE_COMPLETE = '현장 완료'
REPORT = '출장 보고서 작성'
COMPLETE = 'AS 처리 완료'
STYPE = (
(ACCEPT, 'AS 접수'),
(TEAMASSIGNED, '팀 할당'),
(SITE_COMPLETE, '현장 완료'),
(REPORT, '출장 보고서 작성'),
(COMPLETE, 'AS 처리 완료'),
)
ascode = models.CharField("AS 코드", max_length=10, unique=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL,
on_delete=models.SET_NULL,null=True)
customer = models.ForeignKey(CustCompany, on_delete=models.SET_NULL,
blank=True, null=True, verbose_name='고객사 명')
project_name = models.CharField("Project 명", max_length=100, default='')
representative = models.ForeignKey(Representative, on_delete=models.CASCADE,
blank=True, null=True, verbose_name='고객 담당자')
....
# AS 담당자 지정 2019년 1월 21일
asmans = models.ManyToManyField(settings.AUTH_USER_MODEL, related_name='asmans')
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ('-created_at',)
def __str__(self):
return self.ascode
def get_absolute_url(self):
return reverse('fta:service_detail', args=[self.id])
# 출장비 관련
def get_cost_count(self):
return self.costs.count()
def get_costs(self):
return self.costs.all().order_by('ctype', 'currency')
class Cost(models.Model):
TRAFFIC = 'TRANSPORTATION'
FOOD = 'FOOD'
HOTEL = 'HOTEL'
BUSINESS = 'TRIP'
ETC = 'ETC'
CTYPE = (
(TRAFFIC, 'TRANSPORTATION'),
(FOOD, 'FOOD'),
(HOTEL, 'HOTEL'),
(BUSINESS, 'TRIP'),
(ETC, 'ETC'),
)
KOREAN = 'KRW'
RMB = 'CHINA¥'
JPN = 'JAPAN¥'
DOLLAR = 'DOLLAR'
CURRENCY = (
(KOREAN, 'KRW'),
(RMB, 'CHINA¥'),
(JPN, 'JAPAN¥'),
(DOLLAR, 'DOLLAR'),
)
service = models.ForeignKey(Service, on_delete=models.CASCADE,
related_name='costs')
ctype = models.CharField("비용 구분", max_length=50,
choices=CTYPE, default=TRAFFIC)
content = models.CharField("사용 내역", max_length=100,
blank=True, null=True)
currency = models.CharField("환율", max_length=10,
choices=CURRENCY, default=KOREAN)
cost = models.PositiveIntegerField()
author = models.ForeignKey(settings.AUTH_USER_MODEL,
on_delete=models.SET_NULL,null=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment