Commit 626e0caf by Low

initial load

parent e82254eb
......@@ -13,6 +13,7 @@ class Transaction(models.Model):
status = fields.Selection([
('pending', 'Pending'),
('complete', 'Complete'),
('cancel','Cancel'),
], string="Status", default="pending", required=1)
created_date = fields.Date(string="Created Date", required=True, default=fields.Date.today())
......@@ -47,12 +48,12 @@ class Transaction(models.Model):
return {'domain': {'pet_ids': [('pet_shop_id', '=', record.pet_shop_id.id), ('pet_status', '=', 'available')]}}
# For many2many, if transaction status & pet status is complete OR sold, it will change to pending & available
@api.multi
def action_pending(self):
for record in self:
record.status = 'pending' #change transaction status to pending & run transaction status first
for s1 in record.pet_ids:
s1.pet_status = 'available' #change pet status from pet.py to pending & run pet status
# @api.multi
# def action_pending(self):
# for record in self:
# record.status = 'pending' #change transaction status to pending & run transaction status first
# for s1 in record.pet_ids:
# s1.pet_status = 'available' #change pet status from pet.py to pending & run pet status
@api.multi
def action_complete(self):
......@@ -61,6 +62,14 @@ class Transaction(models.Model):
for s2 in record.pet_ids:
s2.pet_status = 'sold' #change pet status from pet.py to sold & run pet status
@api.multi
def action_cancel(self):
for record in self:
record.status = 'cancel'
for pet in record.pet_ids:
pet.pet_status = 'available'
# Auto-generate transaction ID
@api.model
def create(self, vals):
......@@ -70,8 +79,8 @@ class Transaction(models.Model):
return super(Transaction, self).create(vals)
# Validation Error, validate the transaction status
@api.constrains('status')
def validate_status(self):
for pet in self.pet_ids:
if pet.pet_status == 'sold':
raise ValidationError('Pet is sold')
\ No newline at end of file
# @api.constrains('status')
# def validate_status(self):
# for pet in self.pet_ids:
# if pet.pet_status == 'sold':
# raise ValidationError('Pet is sold')
\ No newline at end of file
......@@ -4,19 +4,63 @@
<t t-call="web.html_container">
<t t-foreach="docs" t-as="doc">
<t t-call="web.external_layout">
<div class="title">
<h2 style="text-align: center;">Pet Transaction Report</h2><br/>
</div>
<div class="page">
<h2 style="text-align: center;">Pet Transaction</h2><br/>
<record id="report_pet_transaction" model="report.paperformat">
<field name="transaction_id">Transaction ID : <t t-esc="doc.transaction"/></field>
<br/>
<field name="customer_name">Customer Name : <t t-esc="doc.customer_id.name"/></field>
<br/>
<field name="tran_status">Transaction Status : <t t-esc="doc.status"/></field>
<br/>
<field name="created_date">Created Date : <t t-esc="doc.created_date"/></field>
<br/>
</record>
<p>Transaction ID : <t t-esc="doc.transaction"/></p>
<p>Customer's Name : <t t-esc="doc.customer_id.name"/></p>
<p>Created Date : <t t-esc="doc.created_date"/></p>
<p>Transaction Status : <t t-esc="doc.status"/></p>
</div>
<br/>
<table class="table">
<thead>
<h5><b>Pet Infomation</b></h5>
<tr>
<th scope="col">Pet(s) Name</th>
<th scope="col">Type</th>
<th scope="col">Age</th>
<th scope="col">Pet's Shop</th>
<th scope="col">Date of Birth</th>
<th scope="col">Price (RM)</th>
<th scope="col">Pet Status</th>
</tr>
</thead>
<body>
<tr t-foreach="doc.pet_ids" t-as="l">
<td>
<span t-field="l.name"/>
</td>
<td>
<span t-field="l.ptype"/>
</td>
<td>
<span t-field="l.age"/>
</td>
<td>
<span t-field="l.pet_shop_id"/>
</td>
<td>
<span t-field="l.dob"/>
</td>
<td>
<span t-esc="'%.2f'% l.price"/>
</td>
<td>
<span t-field="l.pet_status"/>
</td>
</tr>
</body>
</table>
<br/>
<h4 style="text-align: right;">
<b>Total Pet(s) Price (RM): <t t-esc="'%.2f'% doc.total_amount"/></b>
</h4>
</t>
</t>
</t>
......
......@@ -32,17 +32,19 @@
<field name="arch" type="xml">
<form string="Transaction">
<header>
<button name="action_pending" type="object" string="Pending" class="oe_highlight"
attrs="{'invisible': [('status','=','pending')]}" />
<!-- <button name="action_pending" type="object" string="Pending" class="oe_highlight"
attrs="{'invisible': [('status','=','pending')]}" /> -->
<button name="action_complete" type="object" string="Complete" class="oe_highlight"
attrs="{'invisible': [('status','=','complete')]}"/>
<button name="action_cancel" type="object" string="Cancel" class="oe_highlight"
attrs="{'invisible': [('status','=','cancel')]}"/>
<field name="status" widget="statusbar" statusbar_visible="pending,complete"/>
</header>
<group string="Transaction Info">
<field name="transaction" readonly="1" force_save="1"/>
<field name="customer_id"/>
<field name="pet_shop_id"/>
<field name="pet_ids"/> <!--domain="[('pet_shop_id', '=', 'pet_shop_id'), ('pet_ids', '=', 'pet_ids')]"-->
<field name="customer_id" attrs="{'readonly': [('status','in',['complete','cancel'])]}"/>
<field name="pet_shop_id" attrs="{'readonly': [('status','in',['complete','cancel'])]}"/>
<field name="pet_ids" attrs="{'readonly': [('status','in', ['complete','cancel'])]}"/>
<field name="created_date" readonly="1"/>
<field name="total_amount" readonly="1"/>
</group>
......
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