revert to one line per doc
This commit is contained in:
parent
a1f1da6d6d
commit
d85e8ff7d8
Binary file not shown.
@ -37,63 +37,20 @@ type ReqGeneratorService struct {
|
||||
Date string `json:"date"`
|
||||
OrgTaxNum string `json:"orgtaxnum"`
|
||||
OrgName string `json:"orgname"`
|
||||
Sum string `json:"sum"`
|
||||
Goods []ReqGeneratorServiceItem `json:"goods"`
|
||||
}
|
||||
|
||||
type ReqGeneratorServiceItem struct {
|
||||
Name string `json:"name"`
|
||||
Amount string `json:"amount"`
|
||||
Price string `json:"price"`
|
||||
Sum string `json:"sum"`
|
||||
Unit string `json:"unit"` // default value set in NewReqGeneratorService()
|
||||
Tax string `json:"tax"` // default value set in NewReqGeneratorService()
|
||||
}
|
||||
|
||||
// Must be kept in sync with the actual number of rows in docx
|
||||
const ReqGeneratorServiceTemplateRows = 4
|
||||
|
||||
type ReqGeneratorServiceTemplateData struct {
|
||||
DocNumber string
|
||||
Date string
|
||||
OrgTaxNum string
|
||||
OrgName string
|
||||
Sum string
|
||||
X []ReqGeneratorServiceTemplateDataItem // single letter to produce less noise inside template
|
||||
}
|
||||
|
||||
type ReqGeneratorServiceTemplateDataItem struct {
|
||||
Name string
|
||||
Amount string
|
||||
Price string
|
||||
Sum string
|
||||
Nds string
|
||||
Unit string
|
||||
}
|
||||
|
||||
func (r ReqGeneratorService) TemplateData() ReqGeneratorServiceTemplateData {
|
||||
xs := make([]ReqGeneratorServiceTemplateDataItem, ReqGeneratorServiceTemplateRows)
|
||||
for i, v := range r.Goods {
|
||||
xs[i] = ReqGeneratorServiceTemplateDataItem{
|
||||
Name: v.Name,
|
||||
Amount: v.Amount,
|
||||
Price: v.Price,
|
||||
Sum: v.Sum,
|
||||
Nds: "НДС не облагается",
|
||||
func NewReqGeneratorService() ReqGeneratorService {
|
||||
return ReqGeneratorService{
|
||||
Tax: "НДС не облагается",
|
||||
Unit: "-",
|
||||
}
|
||||
}
|
||||
for i := len(r.Goods); i < ReqGeneratorServiceTemplateRows; i++ {
|
||||
xs[i] = ReqGeneratorServiceTemplateDataItem{}
|
||||
}
|
||||
|
||||
return ReqGeneratorServiceTemplateData{
|
||||
DocNumber: r.DocNumber,
|
||||
Date: r.Date,
|
||||
OrgTaxNum: r.OrgTaxNum,
|
||||
OrgName: r.OrgName,
|
||||
Sum: r.Sum,
|
||||
X: xs,
|
||||
}
|
||||
}
|
||||
|
||||
// GeneratorByAmoLead - сгенерировать файл по lead_id и указанному файлу если он установлен,
|
||||
// или по шаблону если файл не указан.
|
||||
|
@ -16,20 +16,18 @@ func TestGeneratorService(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
r := ReqGeneratorService{
|
||||
DocNumber: "2",
|
||||
Date: "13.05.2021",
|
||||
OrgName: `ООО ЛИГА ХОДЬБЫ "ЖЕНЬШЕНЬ" ПРИМОРСКОГО КРАЯ`,
|
||||
OrgTaxNum: "999888111",
|
||||
Sum: "60 000 руб.",
|
||||
Goods: []ReqGeneratorServiceItem{
|
||||
{"Консультационные услуги", "2", "1500", "3000"},
|
||||
{"Развлекательные услуги", "1", "500", "500"},
|
||||
{"Информационные услуги", "10", "1000", "10000"},
|
||||
},
|
||||
}
|
||||
data := NewReqGeneratorService()
|
||||
|
||||
data := r.TemplateData()
|
||||
// is filled by json.Unmarshal
|
||||
data.DocNumber = "2"
|
||||
data.Date = "13.05.2021"
|
||||
data.OrgName = `ООО ЛИГА ХОДЬБЫ "ЖЕНЬШЕНЬ" ПРИМОРСКОГО КРАЯ`
|
||||
data.OrgTaxNum = "999888111"
|
||||
data.Sum = "60 000 руб."
|
||||
data.Name = "Консультационные услуги"
|
||||
data.Amount = "2"
|
||||
data.Price = "1500"
|
||||
data.Sum = "3000"
|
||||
|
||||
resultBytes, err := templategen.GenerateBytesFile(file, data)
|
||||
if err != nil {
|
||||
@ -42,7 +40,7 @@ func TestGeneratorService(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// _ = os.WriteFile("/tmp/out2.docx", resultBytes, 0644) // TODO delete
|
||||
// _ = os.WriteFile("/tmp/out3.docx", resultBytes, 0644) // TODO delete
|
||||
|
||||
checkAllFieldsPresent(t, document.GetContent(), data)
|
||||
}
|
||||
@ -61,10 +59,6 @@ func checkAllFieldsPresent(t *testing.T, content string, data interface{}) {
|
||||
if !strings.Contains(content, x) {
|
||||
t.Errorf("missing value for '%s': '%s'", fieldName, x)
|
||||
}
|
||||
case []ReqGeneratorServiceTemplateDataItem:
|
||||
for _, item := range x {
|
||||
checkAllFieldsPresent(t, content, item)
|
||||
}
|
||||
default:
|
||||
t.Error("unhandled field")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user