refactor models component and componentType
gitea/salix/1965-update_models This commit looks good Details

This commit is contained in:
Bernat Exposito Domenech 2019-12-27 08:01:53 +01:00
parent e4279733f4
commit e9d3b14da7
12 changed files with 28 additions and 28 deletions

View File

@ -8,8 +8,8 @@ describe('sale updatePrice()', () => {
let manaComponentId;
beforeAll(async done => {
let componentRate = await app.models.ComponentRate.findOne({where: {code: 'mana'}});
manaComponentId = componentRate.id;
let component = await app.models.Component.findOne({where: {code: 'mana'}});
manaComponentId = component.id;
originalSale = await app.models.Sale.findById(saleId);
originalSalesPersonMana = await app.models.WorkerMana.findById(18);

View File

@ -59,7 +59,7 @@ module.exports = Self => {
let usesMana = await models.WorkerMana.findOne({where: {workerFk: salesPerson}, fields: 'amount'}, options);
let componentCode = usesMana ? 'mana' : 'buyerDiscount';
let discount = await models.ComponentRate.findOne({where: {code: componentCode}}, options);
let discount = await models.Component.findOne({where: {code: componentCode}}, options);
let componentId = discount.id;
let componentValue = newPrice - sale.price;

View File

@ -13,7 +13,7 @@ describe('ticket componentUpdate()', () => {
let componentOfSaleEight;
beforeAll(async done => {
let deliveryComponenet = await app.models.ComponentRate.findOne({where: {code: 'delivery'}});
let deliveryComponenet = await app.models.Component.findOne({where: {code: 'delivery'}});
deliveryComponentId = deliveryComponenet.id;
componentOfSaleSeven = `SELECT value FROM vn.saleComponent WHERE saleFk = 7 AND componentFk = ${deliveryComponentId}`;
componentOfSaleEight = `SELECT value FROM vn.saleComponent WHERE saleFk = 8 AND componentFk = ${deliveryComponentId}`;

View File

@ -8,7 +8,7 @@ describe('sale updateDiscount()', () => {
beforeAll(async done => {
originalSale = await app.models.Sale.findById(originalSaleId);
let manaDiscount = await app.models.ComponentRate.findOne({where: {code: 'mana'}});
let manaDiscount = await app.models.Component.findOne({where: {code: 'mana'}});
componentId = manaDiscount.id;
let ticket = await app.models.Ticket.findById(originalSale.ticketFk);

View File

@ -88,7 +88,7 @@ module.exports = Self => {
fields: 'amount'}, options);
const componentCode = usesMana ? 'mana' : 'buyerDiscount';
const discountComponent = await models.ComponentRate.findOne({
const discountComponent = await models.Component.findOne({
where: {code: componentCode}}, options);
const componentId = discountComponent.id;

View File

@ -5,10 +5,10 @@
"AnnualAverageInvoiced": {
"dataSource": "vn"
},
"ComponentRate": {
"Component": {
"dataSource": "vn"
},
"ComponentTypeRate": {
"ComponentType": {
"dataSource": "vn"
},
"Expedition": {

View File

@ -1,5 +1,5 @@
{
"name": "ComponentTypeRate",
"name": "ComponentType",
"base": "VnModel",
"options": {
"mysql": {

View File

@ -1,5 +1,5 @@
{
"name": "ComponentRate",
"name": "Component",
"base": "VnModel",
"options": {
"mysql": {
@ -34,7 +34,7 @@
"relations": {
"componentType": {
"type": "belongsTo",
"model": "ComponentTypeRate",
"model": "ComponentType",
"foreignKey": "typeFk"
}
},

View File

@ -25,9 +25,9 @@
"model": "Sale",
"foreignKey": "saleFk"
},
"componentRate": {
"component": {
"type": "belongsTo",
"model": "ComponentRate",
"model": "Component",
"foreignKey": "componentFk"
}
}

View File

@ -45,19 +45,19 @@
</td>
</tr>
<tr
ng-repeat="component in sale.components track by component.componentFk"
ng-repeat="saleComponent in sale.components track by saleComponent.componentFk"
class="components">
<td>
{{::component.componentRate.componentType.type}}
{{::saleComponent.component.componentType.type}}
</td>
<td>
{{::component.componentRate.name}}
{{::saleComponent.component.name}}
</td>
<td number>
{{::component.value | currency: 'EUR':3}}
{{::saleComponent.value | currency: 'EUR':3}}
</td>
<td number>
{{::sale.quantity * component.value | currency: 'EUR':3}}
{{::sale.quantity * saleComponent.value | currency: 'EUR':3}}
</td>
</tr>
</tbody>

View File

@ -15,7 +15,7 @@ class Controller {
scope: {
fields: ['componentFk', 'value'],
include: {
relation: 'componentRate',
relation: 'component',
scope: {
fields: ['typeFk', 'name'],
include: {
@ -38,9 +38,9 @@ class Controller {
if (!sales) return;
for (let sale of sales) {
for (let component of sale.components) {
if (component.componentRate.componentType.isBase)
sum += sale.quantity * component.value;
for (let saleComponent of sale.components) {
if (saleComponent.component.componentType.isBase)
sum += sale.quantity * saleComponent.value;
}
}

View File

@ -14,7 +14,7 @@ describe('ticket', () => {
$scope.model.data = [{
components: [
{
componentRate: {
component: {
name: 'valor de compra',
componentType: {
isBase: 1
@ -23,7 +23,7 @@ describe('ticket', () => {
value: 5
},
{
componentRate: {
component: {
name: 'reparto',
componentType: {
isBase: 0
@ -32,7 +32,7 @@ describe('ticket', () => {
value: 5
},
{
componentRate: {
component: {
name: 'recobro',
componentType: {
isBase: 0
@ -46,7 +46,7 @@ describe('ticket', () => {
{
components: [
{
componentRate: {
component: {
name: 'valor de compra',
componentType: {
isBase: 1
@ -55,7 +55,7 @@ describe('ticket', () => {
value: 1
},
{
componentRate: {
component: {
name: 'reparto',
componentType: {
isBase: 0
@ -64,7 +64,7 @@ describe('ticket', () => {
value: 1
},
{
componentRate: {
component: {
name: 'recobro',
componentType: {
isBase: 0