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; let manaComponentId;
beforeAll(async done => { beforeAll(async done => {
let componentRate = await app.models.ComponentRate.findOne({where: {code: 'mana'}}); let component = await app.models.Component.findOne({where: {code: 'mana'}});
manaComponentId = componentRate.id; manaComponentId = component.id;
originalSale = await app.models.Sale.findById(saleId); originalSale = await app.models.Sale.findById(saleId);
originalSalesPersonMana = await app.models.WorkerMana.findById(18); 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 usesMana = await models.WorkerMana.findOne({where: {workerFk: salesPerson}, fields: 'amount'}, options);
let componentCode = usesMana ? 'mana' : 'buyerDiscount'; 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 componentId = discount.id;
let componentValue = newPrice - sale.price; let componentValue = newPrice - sale.price;

View File

@ -13,7 +13,7 @@ describe('ticket componentUpdate()', () => {
let componentOfSaleEight; let componentOfSaleEight;
beforeAll(async done => { 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; deliveryComponentId = deliveryComponenet.id;
componentOfSaleSeven = `SELECT value FROM vn.saleComponent WHERE saleFk = 7 AND componentFk = ${deliveryComponentId}`; componentOfSaleSeven = `SELECT value FROM vn.saleComponent WHERE saleFk = 7 AND componentFk = ${deliveryComponentId}`;
componentOfSaleEight = `SELECT value FROM vn.saleComponent WHERE saleFk = 8 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 => { beforeAll(async done => {
originalSale = await app.models.Sale.findById(originalSaleId); 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; componentId = manaDiscount.id;
let ticket = await app.models.Ticket.findById(originalSale.ticketFk); let ticket = await app.models.Ticket.findById(originalSale.ticketFk);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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