fix issues in sales and purchases module.

This commit is contained in:
Ahmed Bouhuolia
2020-08-05 16:25:53 +02:00
parent ad772cf247
commit 57ec5bdfbe
12 changed files with 236 additions and 62 deletions

View File

@@ -19,40 +19,27 @@ export default class BillPayment extends mixin(TenantModel, [CachableModel]) {
return ['createdAt', 'updatedAt'];
}
/**
* Extend query builder model.
*/
static get QueryBuilder() {
return CachableQueryBuilder;
}
static changePaymentAmount(billId, amount) {
const changeMethod = amount > 0 ? 'increment' : 'decrement';
return this.tenant()
.query()
.where('id', billId)
[changeMethod]('payment_amount', Math.abs(amount));
}
/**
* Relationship mapping.
*/
static get relationMappings() {
const BillPaymentEntry = require('@/models/BillPaymentEntry');
const Vendor = require('@/models/Vendor');
const Account = require('@/models/Account');
return {
/**
*
*/
entries: {
relation: Model.BelongsToOneRelation,
relation: Model.HasManyRelation,
modelClass: this.relationBindKnex(BillPaymentEntry.default),
join: {
from: 'bills_payments.id',
to: 'bills_payments_entries.billPaymentId',
},
},
/**
*
*/
@@ -63,7 +50,19 @@ export default class BillPayment extends mixin(TenantModel, [CachableModel]) {
from: 'bills_payments.vendorId',
to: 'vendors.id',
},
}
},
/**
*
*/
paymentAccount: {
relation: Model.BelongsToOneRelation,
modelClass: this.relationBindKnex(Account.default),
join: {
from: 'bills_payments.paymentAccountId',
to: 'accounts.id',
},
},
};
}
}