fix: Graph fetch relations with sales & purchases models.

feat: Inventory tracker algorithm lots with FIFO or LIFO cost method.
This commit is contained in:
Ahmed Bouhuolia
2020-08-11 01:00:33 +02:00
parent 8d4b3f1ab3
commit 42569c89e4
25 changed files with 526 additions and 93 deletions

View File

@@ -24,8 +24,29 @@ export default class PaymentReceive extends mixin(TenantModel, [CachableModel])
*/
static get relationMappings() {
const PaymentReceiveEntry = require('@/models/PaymentReceiveEntry');
const AccountTransaction = require('@/models/AccountTransaction');
const Customer = require('@/models/Customer');
const Account = require('@/models/Account');
return {
customer: {
relation: Model.BelongsToOneRelation,
modelClass: this.relationBindKnex(Customer.default),
join: {
from: 'payment_receives.customerId',
to: 'customers.id',
},
},
depositAccount: {
relation: Model.BelongsToOneRelation,
modelClass: this.relationBindKnex(Account.default),
join: {
from: 'payment_receives.depositAccountId',
to: 'accounts.id',
},
},
entries: {
relation: Model.HasManyRelation,
modelClass: this.relationBindKnex(PaymentReceiveEntry.default),
@@ -34,6 +55,18 @@ export default class PaymentReceive extends mixin(TenantModel, [CachableModel])
to: 'payment_receives_entries.paymentReceiveId',
},
},
transactions: {
relation: Model.HasManyRelation,
modelClass: this.relationBindKnex(AccountTransaction.default),
join: {
from: 'payment_receives.id',
to: 'accounts_transactions.referenceId'
},
filter(builder) {
builder.where('reference_type', 'PaymentReceive');
},
}
};
}
}