inherit report_stock_card

stable
watcha.h 2016-03-09 12:06:14 +07:00
parent 421ec99363
commit 342f07502b
3 changed files with 346 additions and 0 deletions

View File

@ -145,3 +145,4 @@ from . import invoice_payment
from . import document
from . import payment_matching
from . import create_invoice_payment
from . import report_stock_card

View File

@ -0,0 +1,81 @@
from netforce.model import Model, get_model
from netforce.access import get_active_company
class ReportStockCard(Model):
_inherit="report.stock.card"
def get_report_data(self,ids,context={}):
company=get_model("company").browse(get_active_company())
defaults=self.default_get(context=context)
location_id=defaults.get("location_id")
date_from=defaults.get('date_from')
date_to=defaults.get('date_to')
#product_id=defaults.get('product_id')
if not ids and not location_id:
return {
'date_from': date_from,
'date_to': date_to,
'company_name': company.name,
}
data={
'loc_view': False,
}
if ids:
obj=self.browse(ids)[0]
location=obj.location_id
loc_view_id=location.id
if location.type=='view':
data.update({
'loc_view': True,
'date_from': obj.date_from,
'date_to': obj.date_to,
'company_name': company.name,
})
child_ids=get_model('stock.location').search([['parent_id','=',location.id]])
locs={}
for child_id in child_ids:
obj.write({
'location_id': child_id,
})
groups=super().get_report_data(ids,context)['groups']
for group in groups:
location_id=group['location_id']
locs.setdefault(location_id,{
'total_in_amount': 0,
'total_in_qty': 0,
'total_in_qty2': 0,
'total_out_amount': 0,
'total_out_qty': 0,
'total_out_qty2': 0,
})
locs[location_id]['total_in_amount']+=group['total_in_amount']
locs[location_id]['total_in_qty']+=group['total_in_qty']
locs[location_id]['total_in_qty2']+=group['total_in_qty2']
locs[location_id]['total_out_amount']+=group['total_out_amount']
locs[location_id]['total_out_qty']+=group['total_out_qty']
locs[location_id]['total_out_qty2']+=group['total_out_qty2']
lines=[]
for loc_id,vals in locs.items():
vals['total_bl_qty']=vals['total_in_qty']-vals['total_out_qty']
vals['total_bl_amount']=vals['total_in_amount']-vals['total_out_amount']
vals['total_bl_qty2']=vals['total_in_qty2']-vals['total_out_qty2']
location=get_model('stock.location').browse(loc_id)
vals.update({
'loc_id': loc_id,
'loc_name': location.name,
})
lines.append(vals)
obj.write({
'location_id': loc_view_id,
})
data.update({
'lines': lines,
'show_qty2': True,
})
else:
data.update(super().get_report_data(ids,context))
else:
data.update(super().get_report_data(ids,context))
return data
ReportStockCard.register()

View File

@ -0,0 +1,264 @@
<center>
<h2>
Stock Card
</h2>
<h3>
{{company_name}}
</h3>
<h4>
From {{date_from}} to {{date_to}}
</h4>
</center>
{{#if loc_view}}
<table class="table table-bordered">
<thead>
<tr>
<th rowspan="2">Location</th>
<th colspan="{{#if show_qty2}}3{{else}}2{{/if}}" style="text-align:center">In</th>
<th colspan="{{#if show_qty2}}3{{else}}2{{/if}}" style="text-align:center">Out</th>
<th colspan="{{#if show_qty2}}3{{else}}2{{/if}}" style="text-align:center">Balance</th>
</tr>
<tr>
<th>
Qty
</th>
<th>
Amount
</th>
{{#if show_qty2}}
<th>
Secondary Qty
</th>
{{/if}}
<th>
Qty
</th>
<th>
Amount
</th>
{{#if show_qty2}}
<th>
Secondary Qty
</th>
{{/if}}
<th>
Qty
</th>
<th>
Amount
</th>
{{#if show_qty2}}
<th>
Secondary Qty
</th>
{{/if}}
</tr>
</thead>
<tbody>
{{#each lines}}
<tr>
<td>
<a href="ui#name=report_stock_card&defaults.location_id={{loc_id}}&defaults.date_from{{../date_from}}&defaults.date_to={{../date_to}}">
{{loc_name}}
</a>
</td>
<td>
{{currency total_in_qty}}
</td>
<td>
{{currency total_in_amount}}
</td>
<td>
{{currency total_in_qty2}}
</td>
<td>
{{currency total_out_qty}}
</td>
<td>
{{currency total_out_amount}}
</td>
<td>
{{currency total_out_qty2}}
</td>
<td>
{{currency total_bl_qty}}
</td>
<td>
{{currency total_bl_amount}}
</td>
<td>
{{currency total_bl_qty2}}
</td>
</tr>
{{/each}}
</tbody>
<tfoot>
</tfoot>
</table>
{{else}}
<table class="table table-bordered">
<thead>
<tr>
<th rowspan="2">Date</th>
<th rowspan="2">Ref</th>
<th rowspan="2">Lot / Serial Number</th>
<th rowspan="2">Invoice</th>
<th colspan="{{#if show_qty2}}4{{else}}3{{/if}}" style="text-align:center">In</th>
<th colspan="{{#if show_qty2}}4{{else}}3{{/if}}" style="text-align:center">Out</th>
<th colspan="{{#if show_qty2}}4{{else}}3{{/if}}" style="text-align:center">Balance</th>
</tr>
<tr>
<th>
Qty
</th>
<th>
Unit Price
</th>
<th>
Amount
</th>
{{#if show_qty2}}
<th>
Secondary Qty
</th>
{{/if}}
<th>
Qty
</th>
<th>
Unit Price
</th>
<th>
Amount
</th>
{{#if show_qty2}}
<th>
Secondary Qty
</th>
{{/if}}
<th>
Qty
</th>
<th>
Cost Price
</th>
<th>
Cost Amount
</th>
{{#if show_qty2}}
<th>
Secondary Qty
</th>
{{/if}}
</tr>
</thead>
<tbody>
{{#each groups context=context}}
<tr>
<th colspan="20">
{{product_name}}
@ {{location_name}}
</th>
</tr>
{{#each lines context=context}}
<tr>
<td>
{{date}}
</td>
<td>
{{view "link" string=ref action="view_stock_transaction" active_id=id context=context}}
</td>
<td>
{{view "link" string=lot_num action="stock_lot" action_options="mode=form" active_id=lot_id context=context}}
</td>
<td>
{{view "link" string=invoice_num action="view_invoice" active_id=invoice_id context=context}}
</td>
<td>
{{currency in_qty}}
</td>
<td>
{{currency in_unit_price}}
</td>
<td>
{{currency in_amount}}
</td>
{{#if ../../show_qty2}}
<td>
{{currency in_qty2}}
</td>
{{/if}}
<td>
{{currency out_qty}}
</td>
<td>
{{currency out_unit_price}}
</td>
<td>
{{currency out_amount}}
</td>
{{#if ../../show_qty2}}
<td>
{{currency out_qty2}}
</td>
{{/if}}
<td>
{{currency bal_qty}}
</td>
<td>
{{currency bal_cost_price}}
</td>
<td>
{{currency bal_cost_amount}}
</td>
{{#if ../../show_qty2}}
<td>
{{currency bal_qty2}}
</td>
{{/if}}
</tr>
{{/each}}
<tr>
<td>
</td>
<th>
Total
</th>
<td>
</td>
<td>
</td>
<th>
{{currency total_in_qty}}
</th>
<td>
</td>
<th>
{{currency total_in_amount}}
</th>
{{#if ../show_qty2}}
<th>
{{currency total_in_qty2}}
</th>
{{/if}}
<th>
{{currency total_out_qty}}
</th>
<td>
</td>
<th>
{{currency total_out_amount}}
</th>
{{#if ../show_qty2}}
<th>
{{currency total_out_qty2}}
</th>
{{/if}}
<th></th>
<th></th>
<th></th>
</tr>
{{/each}}
</tbody>
</table>
{{/if}}